streamly-0.8.3: Dataflow programming and declarative concurrency
Copyright(c) 2018 Composewell Technologies
LicenseBSD3
Maintainerstreamly@composewell.com
Stabilitypre-release
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageHaskell2010

Streamly.Internal.Data.List

Description

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:

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.

Synopsis

Documentation

newtype List a Source #

List a is a replacement for [a].

Since: 0.6.0

Constructors

List 

Bundled Patterns

pattern Nil :: List a

An empty list constructor and pattern that matches an empty List. Corresponds to '[]' for Haskell lists.

Since: 0.6.0

pattern Cons :: a -> List a -> List a infixr 5

A list constructor and pattern that deconstructs a List into its head and tail. Corresponds to : for Haskell lists.

Since: 0.6.0

Instances

Instances details
Foldable List Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

fold :: Monoid m => List m -> m #

foldMap :: Monoid m => (a -> m) -> List a -> m #

foldMap' :: Monoid m => (a -> m) -> List a -> m #

foldr :: (a -> b -> b) -> b -> List a -> b #

foldr' :: (a -> b -> b) -> b -> List a -> b #

foldl :: (b -> a -> b) -> b -> List a -> b #

foldl' :: (b -> a -> b) -> b -> List a -> b #

foldr1 :: (a -> a -> a) -> List a -> a #

foldl1 :: (a -> a -> a) -> List a -> a #

toList :: List a -> [a] #

null :: List a -> Bool #

length :: List a -> Int #

elem :: Eq a => a -> List a -> Bool #

maximum :: Ord a => List a -> a #

minimum :: Ord a => List a -> a #

sum :: Num a => List a -> a #

product :: Num a => List a -> a #

Traversable List Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

traverse :: Applicative f => (a -> f b) -> List a -> f (List b) #

sequenceA :: Applicative f => List (f a) -> f (List a) #

mapM :: Monad m => (a -> m b) -> List a -> m (List b) #

sequence :: Monad m => List (m a) -> m (List a) #

Applicative List Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

pure :: a -> List a #

(<*>) :: List (a -> b) -> List a -> List b #

liftA2 :: (a -> b -> c) -> List a -> List b -> List c #

(*>) :: List a -> List b -> List b #

(<*) :: List a -> List b -> List a #

Functor List Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

fmap :: (a -> b) -> List a -> List b #

(<$) :: a -> List b -> List a #

Monad List Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

(>>=) :: List a -> (a -> List b) -> List b #

(>>) :: List a -> List b -> List b #

return :: a -> List a #

NFData1 List Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

liftRnf :: (a -> ()) -> List a -> () #

a ~ Char => IsString (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

fromString :: String -> List a #

Monoid (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

mempty :: List a #

mappend :: List a -> List a -> List a #

mconcat :: [List a] -> List a #

Semigroup (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

(<>) :: List a -> List a -> List a #

sconcat :: NonEmpty (List a) -> List a #

stimes :: Integral b => b -> List a -> List a #

IsList (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Associated Types

type Item (List a) #

Methods

fromList :: [Item (List a)] -> List a #

fromListN :: Int -> [Item (List a)] -> List a #

toList :: List a -> [Item (List a)] #

Read a => Read (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Show a => Show (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

showsPrec :: Int -> List a -> ShowS #

show :: List a -> String #

showList :: [List a] -> ShowS #

NFData a => NFData (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

rnf :: List a -> () #

Eq a => Eq (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

(==) :: List a -> List a -> Bool #

(/=) :: List a -> List a -> Bool #

Ord a => Ord (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

compare :: 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 #

max :: List a -> List a -> List a #

min :: List a -> List a -> List a #

type Item (List a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

type Item (List a) = a

newtype ZipList a Source #

Just like List except that it has a zipping Applicative instance and no Monad instance.

Since: 0.6.0

Constructors

ZipList 

Instances

Instances details
Foldable ZipList Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

fold :: Monoid m => ZipList m -> m #

foldMap :: Monoid m => (a -> m) -> ZipList a -> m #

foldMap' :: Monoid m => (a -> m) -> ZipList a -> m #

foldr :: (a -> b -> b) -> b -> ZipList a -> b #

foldr' :: (a -> b -> b) -> b -> ZipList a -> b #

foldl :: (b -> a -> b) -> b -> ZipList a -> b #

foldl' :: (b -> a -> b) -> b -> ZipList a -> b #

foldr1 :: (a -> a -> a) -> ZipList a -> a #

foldl1 :: (a -> a -> a) -> ZipList a -> a #

toList :: ZipList a -> [a] #

null :: ZipList a -> Bool #

length :: ZipList a -> Int #

elem :: Eq a => a -> ZipList a -> Bool #

maximum :: Ord a => ZipList a -> a #

minimum :: Ord a => ZipList a -> a #

sum :: Num a => ZipList a -> a #

product :: Num a => ZipList a -> a #

Traversable ZipList Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

traverse :: Applicative f => (a -> f b) -> ZipList a -> f (ZipList b) #

sequenceA :: Applicative f => ZipList (f a) -> f (ZipList a) #

mapM :: Monad m => (a -> m b) -> ZipList a -> m (ZipList b) #

sequence :: Monad m => ZipList (m a) -> m (ZipList a) #

Applicative ZipList Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

pure :: a -> ZipList a #

(<*>) :: ZipList (a -> b) -> ZipList a -> ZipList b #

liftA2 :: (a -> b -> c) -> ZipList a -> ZipList b -> ZipList c #

(*>) :: ZipList a -> ZipList b -> ZipList b #

(<*) :: ZipList a -> ZipList b -> ZipList a #

Functor ZipList Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

fmap :: (a -> b) -> ZipList a -> ZipList b #

(<$) :: a -> ZipList b -> ZipList a #

NFData1 ZipList Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

liftRnf :: (a -> ()) -> ZipList a -> () #

a ~ Char => IsString (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

fromString :: String -> ZipList a #

Monoid (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

mempty :: ZipList a #

mappend :: ZipList a -> ZipList a -> ZipList a #

mconcat :: [ZipList a] -> ZipList a #

Semigroup (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

(<>) :: ZipList a -> ZipList a -> ZipList a #

sconcat :: NonEmpty (ZipList a) -> ZipList a #

stimes :: Integral b => b -> ZipList a -> ZipList a #

IsList (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Associated Types

type Item (ZipList a) #

Methods

fromList :: [Item (ZipList a)] -> ZipList a #

fromListN :: Int -> [Item (ZipList a)] -> ZipList a #

toList :: ZipList a -> [Item (ZipList a)] #

Read a => Read (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Show a => Show (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

showsPrec :: Int -> ZipList a -> ShowS #

show :: ZipList a -> String #

showList :: [ZipList a] -> ShowS #

NFData a => NFData (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

rnf :: ZipList a -> () #

Eq a => Eq (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

(==) :: ZipList a -> ZipList a -> Bool #

(/=) :: ZipList a -> ZipList a -> Bool #

Ord a => Ord (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

Methods

compare :: 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 #

max :: ZipList a -> ZipList a -> ZipList a #

min :: ZipList a -> ZipList a -> ZipList a #

type Item (ZipList a) Source # 
Instance details

Defined in Streamly.Internal.Data.List

type Item (ZipList a) = a

fromZipList :: ZipList a -> List a Source #

Convert a ZipList to a regular List

Since: 0.6.0

toZipList :: List a -> ZipList a Source #

Convert a regular List to a ZipList

Since: 0.6.0