{-# LANGUAGE UndecidableInstances #-}

-- |
-- Module      : Streamly.Internal.Data.List
-- Copyright   : (c) 2018 Composewell Technologies
--
-- License     : BSD3
-- Maintainer  : streamly@composewell.com
-- Stability   : pre-release
-- Portability : GHC
--
-- Lists are just a special case of monadic streams. The stream type @SerialT
-- Identity a@ can be used as a replacement for @[a]@.  The 'List' type in this
-- module is just a newtype wrapper around @SerialT Identity@ for better type
-- inference when using the 'OverloadedLists' GHC extension. @List a@ provides
-- better performance compared to @[a]@. Standard list, string and list
-- comprehension syntax can be used with the 'List' type by enabling
-- 'OverloadedLists', 'OverloadedStrings' and 'MonadComprehensions' GHC
-- extensions.  There would be a slight difference in the 'Show' and 'Read'
-- strings of streamly list as compared to regular lists.
--
-- Conversion to stream types is free, any stream combinator can be used on
-- lists by converting them to streams.  However, for convenience, this module
-- provides combinators that work directly on the 'List' type.
--
--
-- @
-- List $ S.map (+ 1) $ toSerial (1 \`Cons\` Nil)
-- @
--
-- To convert a 'List' to regular lists, you can use any of the following:
--
-- * @toList . toSerial@ and @toSerial . fromList@
-- * 'Data.Foldable.toList' from "Data.Foldable"
-- * 'GHC.Exts.toList' and 'GHC.Exts.fromList' from 'IsList' in "GHC.Exts"
--
-- If you have made use of 'Nil' and 'Cons' constructors in the code and you
-- want to replace streamly lists with standard lists, all you need to do is
-- import these definitions:
--
-- @
-- type List = []
-- pattern Nil <- [] where Nil = []
-- pattern Cons x xs = x : xs
-- infixr 5 `Cons`
-- {-\# COMPLETE Cons, Nil #-}
-- @
--
-- See <src/docs/streamly-vs-lists.md> for more details and
-- <src/test/PureStreams.hs> for comprehensive usage examples.
--
module Streamly.Internal.Data.List
    (
    List (.., Nil, Cons)

    -- XXX we may want to use rebindable syntax for variants instead of using
    -- different types (applicative do and apWith).
    , ZipList (..)
    , fromZipList
    , toZipList
    )
where

import Control.Arrow (second)
import Control.DeepSeq (NFData(..))
#if MIN_VERSION_deepseq(1,4,3)
import Control.DeepSeq (NFData1(..))
#endif
import Data.Functor.Identity (Identity, runIdentity)
#if __GLASGOW_HASKELL__ < 808
import Data.Semigroup (Semigroup(..))
#endif
import GHC.Exts (IsList(..), IsString(..))

import Streamly.Internal.Data.Stream.Serial (SerialT)
import Streamly.Internal.Data.Stream.Zip (ZipSerialM)

import qualified Streamly.Internal.Data.Stream.IsStream as Stream
import qualified Streamly.Internal.Data.Stream.StreamK as K

-- We implement list as a newtype instead of a type synonym to make type
-- inference easier when using -XOverloadedLists and -XOverloadedStrings. When
-- using a stream type the programmer needs to specify the Monad otherwise the
-- type remains ambiguous.
--
-- XXX once we separate consM from IsStream or remove the MonadIO and
-- MonadBaseControlIO dependency from it, then we can make this an instance of
-- IsStream and use the regular polymorphic functions on Lists as well. Once
-- that happens we can change the Show and Read instances as well to use "1 >:
-- 2 >: nil" etc. or should we use a separate constructor indicating the "List"
-- type ":>" for better inference?
--
-- | @List a@ is a replacement for @[a]@.
--
-- @since 0.6.0
newtype List a = List { List a -> SerialT Identity a
toSerial :: SerialT Identity a }
    deriving (Int -> List a -> ShowS
[List a] -> ShowS
List a -> String
(Int -> List a -> ShowS)
-> (List a -> String) -> ([List a] -> ShowS) -> Show (List a)
forall a. Show a => Int -> List a -> ShowS
forall a. Show a => [List a] -> ShowS
forall a. Show a => List a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [List a] -> ShowS
$cshowList :: forall a. Show a => [List a] -> ShowS
show :: List a -> String
$cshow :: forall a. Show a => List a -> String
showsPrec :: Int -> List a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> List a -> ShowS
Show, ReadPrec [List a]
ReadPrec (List a)
Int -> ReadS (List a)
ReadS [List a]
(Int -> ReadS (List a))
-> ReadS [List a]
-> ReadPrec (List a)
-> ReadPrec [List a]
-> Read (List a)
forall a. Read a => ReadPrec [List a]
forall a. Read a => ReadPrec (List a)
forall a. Read a => Int -> ReadS (List a)
forall a. Read a => ReadS [List a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [List a]
$creadListPrec :: forall a. Read a => ReadPrec [List a]
readPrec :: ReadPrec (List a)
$creadPrec :: forall a. Read a => ReadPrec (List a)
readList :: ReadS [List a]
$creadList :: forall a. Read a => ReadS [List a]
readsPrec :: Int -> ReadS (List a)
$creadsPrec :: forall a. Read a => Int -> ReadS (List a)
Read, List a -> List a -> Bool
(List a -> List a -> Bool)
-> (List a -> List a -> Bool) -> Eq (List a)
forall a. Eq a => List a -> List a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: List a -> List a -> Bool
$c/= :: forall a. Eq a => List a -> List a -> Bool
== :: List a -> List a -> Bool
$c== :: forall a. Eq a => List a -> List a -> Bool
Eq, Eq (List a)
Eq (List a)
-> (List a -> List a -> Ordering)
-> (List a -> List a -> Bool)
-> (List a -> List a -> Bool)
-> (List a -> List a -> Bool)
-> (List a -> List a -> Bool)
-> (List a -> List a -> List a)
-> (List a -> List a -> List a)
-> Ord (List a)
List a -> List a -> Bool
List a -> List a -> Ordering
List a -> List a -> List a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (List a)
forall a. Ord a => List a -> List a -> Bool
forall a. Ord a => List a -> List a -> Ordering
forall a. Ord a => List a -> List a -> List a
min :: List a -> List a -> List a
$cmin :: forall a. Ord a => List a -> List a -> List a
max :: List a -> List a -> List a
$cmax :: forall a. Ord a => List a -> List a -> List a
>= :: List a -> List a -> Bool
$c>= :: forall a. Ord a => List a -> List a -> Bool
> :: List a -> List a -> Bool
$c> :: forall a. Ord a => List a -> List a -> Bool
<= :: List a -> List a -> Bool
$c<= :: forall a. Ord a => List a -> List a -> Bool
< :: List a -> List a -> Bool
$c< :: forall a. Ord a => List a -> List a -> Bool
compare :: List a -> List a -> Ordering
$ccompare :: forall a. Ord a => List a -> List a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (List a)
Ord, List a -> ()
(List a -> ()) -> NFData (List a)
forall a. NFData a => List a -> ()
forall a. (a -> ()) -> NFData a
rnf :: List a -> ()
$crnf :: forall a. NFData a => List a -> ()
NFData
#if MIN_VERSION_deepseq(1,4,3)
    , (a -> ()) -> List a -> ()
(forall a. (a -> ()) -> List a -> ()) -> NFData1 List
forall a. (a -> ()) -> List a -> ()
forall (f :: * -> *).
(forall a. (a -> ()) -> f a -> ()) -> NFData1 f
liftRnf :: (a -> ()) -> List a -> ()
$cliftRnf :: forall a. (a -> ()) -> List a -> ()
NFData1
#endif
             , b -> List a -> List a
NonEmpty (List a) -> List a
List a -> List a -> List a
(List a -> List a -> List a)
-> (NonEmpty (List a) -> List a)
-> (forall b. Integral b => b -> List a -> List a)
-> Semigroup (List a)
forall b. Integral b => b -> List a -> List a
forall a. NonEmpty (List a) -> List a
forall a. List a -> List a -> List a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a b. Integral b => b -> List a -> List a
stimes :: b -> List a -> List a
$cstimes :: forall a b. Integral b => b -> List a -> List a
sconcat :: NonEmpty (List a) -> List a
$csconcat :: forall a. NonEmpty (List a) -> List a
<> :: List a -> List a -> List a
$c<> :: forall a. List a -> List a -> List a
Semigroup, Semigroup (List a)
List a
Semigroup (List a)
-> List a
-> (List a -> List a -> List a)
-> ([List a] -> List a)
-> Monoid (List a)
[List a] -> List a
List a -> List a -> List a
forall a. Semigroup (List a)
forall a. List a
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. [List a] -> List a
forall a. List a -> List a -> List a
mconcat :: [List a] -> List a
$cmconcat :: forall a. [List a] -> List a
mappend :: List a -> List a -> List a
$cmappend :: forall a. List a -> List a -> List a
mempty :: List a
$cmempty :: forall a. List a
$cp1Monoid :: forall a. Semigroup (List a)
Monoid, a -> List b -> List a
(a -> b) -> List a -> List b
(forall a b. (a -> b) -> List a -> List b)
-> (forall a b. a -> List b -> List a) -> Functor List
forall a b. a -> List b -> List a
forall a b. (a -> b) -> List a -> List b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> List b -> List a
$c<$ :: forall a b. a -> List b -> List a
fmap :: (a -> b) -> List a -> List b
$cfmap :: forall a b. (a -> b) -> List a -> List b
Functor, a -> List a -> Bool
List m -> m
List a -> [a]
List a -> Bool
List a -> Int
List a -> a
List a -> a
List a -> a
List a -> a
(a -> m) -> List a -> m
(a -> m) -> List a -> m
(a -> b -> b) -> b -> List a -> b
(a -> b -> b) -> b -> List a -> b
(b -> a -> b) -> b -> List a -> b
(b -> a -> b) -> b -> List a -> b
(a -> a -> a) -> List a -> a
(a -> a -> a) -> List a -> a
(forall m. Monoid m => List m -> m)
-> (forall m a. Monoid m => (a -> m) -> List a -> m)
-> (forall m a. Monoid m => (a -> m) -> List a -> m)
-> (forall a b. (a -> b -> b) -> b -> List a -> b)
-> (forall a b. (a -> b -> b) -> b -> List a -> b)
-> (forall b a. (b -> a -> b) -> b -> List a -> b)
-> (forall b a. (b -> a -> b) -> b -> List a -> b)
-> (forall a. (a -> a -> a) -> List a -> a)
-> (forall a. (a -> a -> a) -> List a -> a)
-> (forall a. List a -> [a])
-> (forall a. List a -> Bool)
-> (forall a. List a -> Int)
-> (forall a. Eq a => a -> List a -> Bool)
-> (forall a. Ord a => List a -> a)
-> (forall a. Ord a => List a -> a)
-> (forall a. Num a => List a -> a)
-> (forall a. Num a => List a -> a)
-> Foldable List
forall a. Eq a => a -> List a -> Bool
forall a. Num a => List a -> a
forall a. Ord a => List a -> a
forall m. Monoid m => List m -> m
forall a. List a -> Bool
forall a. List a -> Int
forall a. List a -> [a]
forall a. (a -> a -> a) -> List a -> a
forall m a. Monoid m => (a -> m) -> List a -> m
forall b a. (b -> a -> b) -> b -> List a -> b
forall a b. (a -> b -> b) -> b -> List a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: List a -> a
$cproduct :: forall a. Num a => List a -> a
sum :: List a -> a
$csum :: forall a. Num a => List a -> a
minimum :: List a -> a
$cminimum :: forall a. Ord a => List a -> a
maximum :: List a -> a
$cmaximum :: forall a. Ord a => List a -> a
elem :: a -> List a -> Bool
$celem :: forall a. Eq a => a -> List a -> Bool
length :: List a -> Int
$clength :: forall a. List a -> Int
null :: List a -> Bool
$cnull :: forall a. List a -> Bool
toList :: List a -> [a]
$ctoList :: forall a. List a -> [a]
foldl1 :: (a -> a -> a) -> List a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> List a -> a
foldr1 :: (a -> a -> a) -> List a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> List a -> a
foldl' :: (b -> a -> b) -> b -> List a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> List a -> b
foldl :: (b -> a -> b) -> b -> List a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> List a -> b
foldr' :: (a -> b -> b) -> b -> List a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> List a -> b
foldr :: (a -> b -> b) -> b -> List a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> List a -> b
foldMap' :: (a -> m) -> List a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> List a -> m
foldMap :: (a -> m) -> List a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> List a -> m
fold :: List m -> m
$cfold :: forall m. Monoid m => List m -> m
Foldable
             , Functor List
a -> List a
Functor List
-> (forall a. a -> List a)
-> (forall a b. List (a -> b) -> List a -> List b)
-> (forall a b c. (a -> b -> c) -> List a -> List b -> List c)
-> (forall a b. List a -> List b -> List b)
-> (forall a b. List a -> List b -> List a)
-> Applicative List
List a -> List b -> List b
List a -> List b -> List a
List (a -> b) -> List a -> List b
(a -> b -> c) -> List a -> List b -> List c
forall a. a -> List a
forall a b. List a -> List b -> List a
forall a b. List a -> List b -> List b
forall a b. List (a -> b) -> List a -> List b
forall a b c. (a -> b -> c) -> List a -> List b -> List c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: List a -> List b -> List a
$c<* :: forall a b. List a -> List b -> List a
*> :: List a -> List b -> List b
$c*> :: forall a b. List a -> List b -> List b
liftA2 :: (a -> b -> c) -> List a -> List b -> List c
$cliftA2 :: forall a b c. (a -> b -> c) -> List a -> List b -> List c
<*> :: List (a -> b) -> List a -> List b
$c<*> :: forall a b. List (a -> b) -> List a -> List b
pure :: a -> List a
$cpure :: forall a. a -> List a
$cp1Applicative :: Functor List
Applicative, Functor List
Foldable List
Functor List
-> Foldable List
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> List a -> f (List b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    List (f a) -> f (List a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> List a -> m (List b))
-> (forall (m :: * -> *) a. Monad m => List (m a) -> m (List a))
-> Traversable List
(a -> f b) -> List a -> f (List b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => List (m a) -> m (List a)
forall (f :: * -> *) a. Applicative f => List (f a) -> f (List a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> List a -> m (List b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> List a -> f (List b)
sequence :: List (m a) -> m (List a)
$csequence :: forall (m :: * -> *) a. Monad m => List (m a) -> m (List a)
mapM :: (a -> m b) -> List a -> m (List b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> List a -> m (List b)
sequenceA :: List (f a) -> f (List a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => List (f a) -> f (List a)
traverse :: (a -> f b) -> List a -> f (List b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> List a -> f (List b)
$cp2Traversable :: Foldable List
$cp1Traversable :: Functor List
Traversable, Applicative List
a -> List a
Applicative List
-> (forall a b. List a -> (a -> List b) -> List b)
-> (forall a b. List a -> List b -> List b)
-> (forall a. a -> List a)
-> Monad List
List a -> (a -> List b) -> List b
List a -> List b -> List b
forall a. a -> List a
forall a b. List a -> List b -> List b
forall a b. List a -> (a -> List b) -> List b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> List a
$creturn :: forall a. a -> List a
>> :: List a -> List b -> List b
$c>> :: forall a b. List a -> List b -> List b
>>= :: List a -> (a -> List b) -> List b
$c>>= :: forall a b. List a -> (a -> List b) -> List b
$cp1Monad :: Applicative List
Monad)

instance (a ~ Char) => IsString (List a) where
    {-# INLINE fromString #-}
    fromString :: String -> List a
fromString = SerialT Identity a -> List a
forall a. SerialT Identity a -> List a
List (SerialT Identity a -> List a)
-> ([a] -> SerialT Identity a) -> [a] -> List a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> SerialT Identity a
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a.
(Monad m, IsStream t) =>
[a] -> t m a
Stream.fromList

-- GHC versions 8.0 and below cannot derive IsList
instance IsList (List a) where
    type (Item (List a)) = a
    {-# INLINE fromList #-}
    fromList :: [Item (List a)] -> List a
fromList = SerialT Identity a -> List a
forall a. SerialT Identity a -> List a
List (SerialT Identity a -> List a)
-> ([a] -> SerialT Identity a) -> [a] -> List a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> SerialT Identity a
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a.
(Monad m, IsStream t) =>
[a] -> t m a
Stream.fromList
    {-# INLINE toList #-}
    toList :: List a -> [Item (List a)]
toList = Identity [a] -> [a]
forall a. Identity a -> a
runIdentity (Identity [a] -> [a]) -> (List a -> Identity [a]) -> List a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialT Identity a -> Identity [a]
forall (m :: * -> *) a. Monad m => SerialT m a -> m [a]
Stream.toList (SerialT Identity a -> Identity [a])
-> (List a -> SerialT Identity a) -> List a -> Identity [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List a -> SerialT Identity a
forall a. List a -> SerialT Identity a
toSerial

------------------------------------------------------------------------------
-- Patterns
------------------------------------------------------------------------------

-- Note: When using the OverloadedLists extension we should be able to pattern
-- match using the regular list contructors. OverloadedLists uses 'toList' to
-- perform the pattern match, it should not be too bad as it works lazily in
-- the Identity monad. We need these patterns only when not using that
-- extension.
--
-- | An empty list constructor and pattern that matches an empty 'List'.
-- Corresponds to '[]' for Haskell lists.
--
-- @since 0.6.0
pattern Nil :: List a
pattern $bNil :: List a
$mNil :: forall r a. List a -> (Void# -> r) -> (Void# -> r) -> r
Nil <- (runIdentity . K.null . toSerial -> True) where
    Nil = SerialT Identity a -> List a
forall a. SerialT Identity a -> List a
List SerialT Identity a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a
K.nil

infixr 5 `Cons`

-- | A list constructor and pattern that deconstructs a 'List' into its head
-- and tail. Corresponds to ':' for Haskell lists.
--
-- @since 0.6.0
pattern Cons :: a -> List a -> List a
pattern $bCons :: a -> List a -> List a
$mCons :: forall r a. List a -> (a -> List a -> r) -> (Void# -> r) -> r
Cons x xs <-
    (fmap (second List) . runIdentity . K.uncons . toSerial
        -> Just (x, xs)) where
            Cons a
x List a
xs = SerialT Identity a -> List a
forall a. SerialT Identity a -> List a
List (SerialT Identity a -> List a) -> SerialT Identity a -> List a
forall a b. (a -> b) -> a -> b
$ a -> SerialT Identity a -> SerialT Identity a
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
a -> t m a -> t m a
K.cons a
x (List a -> SerialT Identity a
forall a. List a -> SerialT Identity a
toSerial List a
xs)

#if __GLASGOW_HASKELL__ >= 802
{-# COMPLETE Nil, Cons #-}
#endif

------------------------------------------------------------------------------
-- ZipList
------------------------------------------------------------------------------

-- | Just like 'List' except that it has a zipping 'Applicative' instance
-- and no 'Monad' instance.
--
-- @since 0.6.0
newtype ZipList a = ZipList { ZipList a -> ZipSerialM Identity a
toZipSerial :: ZipSerialM Identity a }
    deriving (Int -> ZipList a -> ShowS
[ZipList a] -> ShowS
ZipList a -> String
(Int -> ZipList a -> ShowS)
-> (ZipList a -> String)
-> ([ZipList a] -> ShowS)
-> Show (ZipList a)
forall a. Show a => Int -> ZipList a -> ShowS
forall a. Show a => [ZipList a] -> ShowS
forall a. Show a => ZipList a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ZipList a] -> ShowS
$cshowList :: forall a. Show a => [ZipList a] -> ShowS
show :: ZipList a -> String
$cshow :: forall a. Show a => ZipList a -> String
showsPrec :: Int -> ZipList a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> ZipList a -> ShowS
Show, ReadPrec [ZipList a]
ReadPrec (ZipList a)
Int -> ReadS (ZipList a)
ReadS [ZipList a]
(Int -> ReadS (ZipList a))
-> ReadS [ZipList a]
-> ReadPrec (ZipList a)
-> ReadPrec [ZipList a]
-> Read (ZipList a)
forall a. Read a => ReadPrec [ZipList a]
forall a. Read a => ReadPrec (ZipList a)
forall a. Read a => Int -> ReadS (ZipList a)
forall a. Read a => ReadS [ZipList a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ZipList a]
$creadListPrec :: forall a. Read a => ReadPrec [ZipList a]
readPrec :: ReadPrec (ZipList a)
$creadPrec :: forall a. Read a => ReadPrec (ZipList a)
readList :: ReadS [ZipList a]
$creadList :: forall a. Read a => ReadS [ZipList a]
readsPrec :: Int -> ReadS (ZipList a)
$creadsPrec :: forall a. Read a => Int -> ReadS (ZipList a)
Read, ZipList a -> ZipList a -> Bool
(ZipList a -> ZipList a -> Bool)
-> (ZipList a -> ZipList a -> Bool) -> Eq (ZipList a)
forall a. Eq a => ZipList a -> ZipList a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ZipList a -> ZipList a -> Bool
$c/= :: forall a. Eq a => ZipList a -> ZipList a -> Bool
== :: ZipList a -> ZipList a -> Bool
$c== :: forall a. Eq a => ZipList a -> ZipList a -> Bool
Eq, Eq (ZipList a)
Eq (ZipList a)
-> (ZipList a -> ZipList a -> Ordering)
-> (ZipList a -> ZipList a -> Bool)
-> (ZipList a -> ZipList a -> Bool)
-> (ZipList a -> ZipList a -> Bool)
-> (ZipList a -> ZipList a -> Bool)
-> (ZipList a -> ZipList a -> ZipList a)
-> (ZipList a -> ZipList a -> ZipList a)
-> Ord (ZipList a)
ZipList a -> ZipList a -> Bool
ZipList a -> ZipList a -> Ordering
ZipList a -> ZipList a -> ZipList a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (ZipList a)
forall a. Ord a => ZipList a -> ZipList a -> Bool
forall a. Ord a => ZipList a -> ZipList a -> Ordering
forall a. Ord a => ZipList a -> ZipList a -> ZipList a
min :: ZipList a -> ZipList a -> ZipList a
$cmin :: forall a. Ord a => ZipList a -> ZipList a -> ZipList a
max :: ZipList a -> ZipList a -> ZipList a
$cmax :: forall a. Ord a => ZipList a -> ZipList a -> ZipList a
>= :: ZipList a -> ZipList a -> Bool
$c>= :: forall a. Ord a => ZipList a -> ZipList a -> Bool
> :: ZipList a -> ZipList a -> Bool
$c> :: forall a. Ord a => ZipList a -> ZipList a -> Bool
<= :: ZipList a -> ZipList a -> Bool
$c<= :: forall a. Ord a => ZipList a -> ZipList a -> Bool
< :: ZipList a -> ZipList a -> Bool
$c< :: forall a. Ord a => ZipList a -> ZipList a -> Bool
compare :: ZipList a -> ZipList a -> Ordering
$ccompare :: forall a. Ord a => ZipList a -> ZipList a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (ZipList a)
Ord, ZipList a -> ()
(ZipList a -> ()) -> NFData (ZipList a)
forall a. NFData a => ZipList a -> ()
forall a. (a -> ()) -> NFData a
rnf :: ZipList a -> ()
$crnf :: forall a. NFData a => ZipList a -> ()
NFData
#if MIN_VERSION_deepseq(1,4,3)
    , (a -> ()) -> ZipList a -> ()
(forall a. (a -> ()) -> ZipList a -> ()) -> NFData1 ZipList
forall a. (a -> ()) -> ZipList a -> ()
forall (f :: * -> *).
(forall a. (a -> ()) -> f a -> ()) -> NFData1 f
liftRnf :: (a -> ()) -> ZipList a -> ()
$cliftRnf :: forall a. (a -> ()) -> ZipList a -> ()
NFData1
#endif
             , b -> ZipList a -> ZipList a
NonEmpty (ZipList a) -> ZipList a
ZipList a -> ZipList a -> ZipList a
(ZipList a -> ZipList a -> ZipList a)
-> (NonEmpty (ZipList a) -> ZipList a)
-> (forall b. Integral b => b -> ZipList a -> ZipList a)
-> Semigroup (ZipList a)
forall b. Integral b => b -> ZipList a -> ZipList a
forall a. NonEmpty (ZipList a) -> ZipList a
forall a. ZipList a -> ZipList a -> ZipList a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a b. Integral b => b -> ZipList a -> ZipList a
stimes :: b -> ZipList a -> ZipList a
$cstimes :: forall a b. Integral b => b -> ZipList a -> ZipList a
sconcat :: NonEmpty (ZipList a) -> ZipList a
$csconcat :: forall a. NonEmpty (ZipList a) -> ZipList a
<> :: ZipList a -> ZipList a -> ZipList a
$c<> :: forall a. ZipList a -> ZipList a -> ZipList a
Semigroup, Semigroup (ZipList a)
ZipList a
Semigroup (ZipList a)
-> ZipList a
-> (ZipList a -> ZipList a -> ZipList a)
-> ([ZipList a] -> ZipList a)
-> Monoid (ZipList a)
[ZipList a] -> ZipList a
ZipList a -> ZipList a -> ZipList a
forall a. Semigroup (ZipList a)
forall a. ZipList a
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. [ZipList a] -> ZipList a
forall a. ZipList a -> ZipList a -> ZipList a
mconcat :: [ZipList a] -> ZipList a
$cmconcat :: forall a. [ZipList a] -> ZipList a
mappend :: ZipList a -> ZipList a -> ZipList a
$cmappend :: forall a. ZipList a -> ZipList a -> ZipList a
mempty :: ZipList a
$cmempty :: forall a. ZipList a
$cp1Monoid :: forall a. Semigroup (ZipList a)
Monoid, a -> ZipList b -> ZipList a
(a -> b) -> ZipList a -> ZipList b
(forall a b. (a -> b) -> ZipList a -> ZipList b)
-> (forall a b. a -> ZipList b -> ZipList a) -> Functor ZipList
forall a b. a -> ZipList b -> ZipList a
forall a b. (a -> b) -> ZipList a -> ZipList b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> ZipList b -> ZipList a
$c<$ :: forall a b. a -> ZipList b -> ZipList a
fmap :: (a -> b) -> ZipList a -> ZipList b
$cfmap :: forall a b. (a -> b) -> ZipList a -> ZipList b
Functor, a -> ZipList a -> Bool
ZipList m -> m
ZipList a -> [a]
ZipList a -> Bool
ZipList a -> Int
ZipList a -> a
ZipList a -> a
ZipList a -> a
ZipList a -> a
(a -> m) -> ZipList a -> m
(a -> m) -> ZipList a -> m
(a -> b -> b) -> b -> ZipList a -> b
(a -> b -> b) -> b -> ZipList a -> b
(b -> a -> b) -> b -> ZipList a -> b
(b -> a -> b) -> b -> ZipList a -> b
(a -> a -> a) -> ZipList a -> a
(a -> a -> a) -> ZipList a -> a
(forall m. Monoid m => ZipList m -> m)
-> (forall m a. Monoid m => (a -> m) -> ZipList a -> m)
-> (forall m a. Monoid m => (a -> m) -> ZipList a -> m)
-> (forall a b. (a -> b -> b) -> b -> ZipList a -> b)
-> (forall a b. (a -> b -> b) -> b -> ZipList a -> b)
-> (forall b a. (b -> a -> b) -> b -> ZipList a -> b)
-> (forall b a. (b -> a -> b) -> b -> ZipList a -> b)
-> (forall a. (a -> a -> a) -> ZipList a -> a)
-> (forall a. (a -> a -> a) -> ZipList a -> a)
-> (forall a. ZipList a -> [a])
-> (forall a. ZipList a -> Bool)
-> (forall a. ZipList a -> Int)
-> (forall a. Eq a => a -> ZipList a -> Bool)
-> (forall a. Ord a => ZipList a -> a)
-> (forall a. Ord a => ZipList a -> a)
-> (forall a. Num a => ZipList a -> a)
-> (forall a. Num a => ZipList a -> a)
-> Foldable ZipList
forall a. Eq a => a -> ZipList a -> Bool
forall a. Num a => ZipList a -> a
forall a. Ord a => ZipList a -> a
forall m. Monoid m => ZipList m -> m
forall a. ZipList a -> Bool
forall a. ZipList a -> Int
forall a. ZipList a -> [a]
forall a. (a -> a -> a) -> ZipList a -> a
forall m a. Monoid m => (a -> m) -> ZipList a -> m
forall b a. (b -> a -> b) -> b -> ZipList a -> b
forall a b. (a -> b -> b) -> b -> ZipList a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: ZipList a -> a
$cproduct :: forall a. Num a => ZipList a -> a
sum :: ZipList a -> a
$csum :: forall a. Num a => ZipList a -> a
minimum :: ZipList a -> a
$cminimum :: forall a. Ord a => ZipList a -> a
maximum :: ZipList a -> a
$cmaximum :: forall a. Ord a => ZipList a -> a
elem :: a -> ZipList a -> Bool
$celem :: forall a. Eq a => a -> ZipList a -> Bool
length :: ZipList a -> Int
$clength :: forall a. ZipList a -> Int
null :: ZipList a -> Bool
$cnull :: forall a. ZipList a -> Bool
toList :: ZipList a -> [a]
$ctoList :: forall a. ZipList a -> [a]
foldl1 :: (a -> a -> a) -> ZipList a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> ZipList a -> a
foldr1 :: (a -> a -> a) -> ZipList a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> ZipList a -> a
foldl' :: (b -> a -> b) -> b -> ZipList a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> ZipList a -> b
foldl :: (b -> a -> b) -> b -> ZipList a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> ZipList a -> b
foldr' :: (a -> b -> b) -> b -> ZipList a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> ZipList a -> b
foldr :: (a -> b -> b) -> b -> ZipList a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> ZipList a -> b
foldMap' :: (a -> m) -> ZipList a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> ZipList a -> m
foldMap :: (a -> m) -> ZipList a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> ZipList a -> m
fold :: ZipList m -> m
$cfold :: forall m. Monoid m => ZipList m -> m
Foldable
             , Functor ZipList
a -> ZipList a
Functor ZipList
-> (forall a. a -> ZipList a)
-> (forall a b. ZipList (a -> b) -> ZipList a -> ZipList b)
-> (forall a b c.
    (a -> b -> c) -> ZipList a -> ZipList b -> ZipList c)
-> (forall a b. ZipList a -> ZipList b -> ZipList b)
-> (forall a b. ZipList a -> ZipList b -> ZipList a)
-> Applicative ZipList
ZipList a -> ZipList b -> ZipList b
ZipList a -> ZipList b -> ZipList a
ZipList (a -> b) -> ZipList a -> ZipList b
(a -> b -> c) -> ZipList a -> ZipList b -> ZipList c
forall a. a -> ZipList a
forall a b. ZipList a -> ZipList b -> ZipList a
forall a b. ZipList a -> ZipList b -> ZipList b
forall a b. ZipList (a -> b) -> ZipList a -> ZipList b
forall a b c. (a -> b -> c) -> ZipList a -> ZipList b -> ZipList c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: ZipList a -> ZipList b -> ZipList a
$c<* :: forall a b. ZipList a -> ZipList b -> ZipList a
*> :: ZipList a -> ZipList b -> ZipList b
$c*> :: forall a b. ZipList a -> ZipList b -> ZipList b
liftA2 :: (a -> b -> c) -> ZipList a -> ZipList b -> ZipList c
$cliftA2 :: forall a b c. (a -> b -> c) -> ZipList a -> ZipList b -> ZipList c
<*> :: ZipList (a -> b) -> ZipList a -> ZipList b
$c<*> :: forall a b. ZipList (a -> b) -> ZipList a -> ZipList b
pure :: a -> ZipList a
$cpure :: forall a. a -> ZipList a
$cp1Applicative :: Functor ZipList
Applicative, Functor ZipList
Foldable ZipList
Functor ZipList
-> Foldable ZipList
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> ZipList a -> f (ZipList b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    ZipList (f a) -> f (ZipList a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> ZipList a -> m (ZipList b))
-> (forall (m :: * -> *) a.
    Monad m =>
    ZipList (m a) -> m (ZipList a))
-> Traversable ZipList
(a -> f b) -> ZipList a -> f (ZipList b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => ZipList (m a) -> m (ZipList a)
forall (f :: * -> *) a.
Applicative f =>
ZipList (f a) -> f (ZipList a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ZipList a -> m (ZipList b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ZipList a -> f (ZipList b)
sequence :: ZipList (m a) -> m (ZipList a)
$csequence :: forall (m :: * -> *) a. Monad m => ZipList (m a) -> m (ZipList a)
mapM :: (a -> m b) -> ZipList a -> m (ZipList b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ZipList a -> m (ZipList b)
sequenceA :: ZipList (f a) -> f (ZipList a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
ZipList (f a) -> f (ZipList a)
traverse :: (a -> f b) -> ZipList a -> f (ZipList b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ZipList a -> f (ZipList b)
$cp2Traversable :: Foldable ZipList
$cp1Traversable :: Functor ZipList
Traversable)

instance (a ~ Char) => IsString (ZipList a) where
    {-# INLINE fromString #-}
    fromString :: String -> ZipList a
fromString = ZipSerialM Identity a -> ZipList a
forall a. ZipSerialM Identity a -> ZipList a
ZipList (ZipSerialM Identity a -> ZipList a)
-> ([a] -> ZipSerialM Identity a) -> [a] -> ZipList a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> ZipSerialM Identity a
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a.
(Monad m, IsStream t) =>
[a] -> t m a
Stream.fromList

-- GHC versions 8.0 and below cannot derive IsList
instance IsList (ZipList a) where
    type (Item (ZipList a)) = a
    {-# INLINE fromList #-}
    fromList :: [Item (ZipList a)] -> ZipList a
fromList = ZipSerialM Identity a -> ZipList a
forall a. ZipSerialM Identity a -> ZipList a
ZipList (ZipSerialM Identity a -> ZipList a)
-> ([a] -> ZipSerialM Identity a) -> [a] -> ZipList a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> ZipSerialM Identity a
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a.
(Monad m, IsStream t) =>
[a] -> t m a
Stream.fromList
    {-# INLINE toList #-}
    toList :: ZipList a -> [Item (ZipList a)]
toList = Identity [a] -> [a]
forall a. Identity a -> a
runIdentity (Identity [a] -> [a])
-> (ZipList a -> Identity [a]) -> ZipList a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialT Identity a -> Identity [a]
forall (m :: * -> *) a. Monad m => SerialT m a -> m [a]
Stream.toList (SerialT Identity a -> Identity [a])
-> (ZipList a -> SerialT Identity a) -> ZipList a -> Identity [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZipSerialM Identity a -> SerialT Identity a
forall (t1 :: (* -> *) -> * -> *) (t2 :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(IsStream t1, IsStream t2) =>
t1 m a -> t2 m a
K.adapt (ZipSerialM Identity a -> SerialT Identity a)
-> (ZipList a -> ZipSerialM Identity a)
-> ZipList a
-> SerialT Identity a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZipList a -> ZipSerialM Identity a
forall a. ZipList a -> ZipSerialM Identity a
toZipSerial

-- | Convert a 'ZipList' to a regular 'List'
--
-- @since 0.6.0
fromZipList :: ZipList a -> List a
fromZipList :: ZipList a -> List a
fromZipList = SerialT Identity a -> List a
forall a. SerialT Identity a -> List a
List (SerialT Identity a -> List a)
-> (ZipList a -> SerialT Identity a) -> ZipList a -> List a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZipSerialM Identity a -> SerialT Identity a
forall (t1 :: (* -> *) -> * -> *) (t2 :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(IsStream t1, IsStream t2) =>
t1 m a -> t2 m a
K.adapt (ZipSerialM Identity a -> SerialT Identity a)
-> (ZipList a -> ZipSerialM Identity a)
-> ZipList a
-> SerialT Identity a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZipList a -> ZipSerialM Identity a
forall a. ZipList a -> ZipSerialM Identity a
toZipSerial

-- | Convert a regular 'List' to a 'ZipList'
--
-- @since 0.6.0
toZipList :: List a -> ZipList a
toZipList :: List a -> ZipList a
toZipList = ZipSerialM Identity a -> ZipList a
forall a. ZipSerialM Identity a -> ZipList a
ZipList (ZipSerialM Identity a -> ZipList a)
-> (List a -> ZipSerialM Identity a) -> List a -> ZipList a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SerialT Identity a -> ZipSerialM Identity a
forall (t1 :: (* -> *) -> * -> *) (t2 :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(IsStream t1, IsStream t2) =>
t1 m a -> t2 m a
K.adapt (SerialT Identity a -> ZipSerialM Identity a)
-> (List a -> SerialT Identity a)
-> List a
-> ZipSerialM Identity a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List a -> SerialT Identity a
forall a. List a -> SerialT Identity a
toSerial