Portability | non-portable |
---|---|

Stability | experimental |

Maintainer | Roman Leshchinskiy <rl@cse.unsw.edu.au> |

Monadic streams

- data Stream m a = forall s . Stream (s -> m (Step s a)) s Size
- data Step s a
- size :: Stream m a -> Size
- sized :: Stream m a -> Size -> Stream m a
- length :: Monad m => Stream m a -> m Int
- null :: Monad m => Stream m a -> m Bool
- empty :: Monad m => Stream m a
- singleton :: Monad m => a -> Stream m a
- cons :: Monad m => a -> Stream m a -> Stream m a
- snoc :: Monad m => Stream m a -> a -> Stream m a
- replicate :: Monad m => Int -> a -> Stream m a
- (++) :: Monad m => Stream m a -> Stream m a -> Stream m a
- head :: Monad m => Stream m a -> m a
- last :: Monad m => Stream m a -> m a
- (!!) :: Monad m => Stream m a -> Int -> m a
- extract :: Monad m => Stream m a -> Int -> Int -> Stream m a
- init :: Monad m => Stream m a -> Stream m a
- tail :: Monad m => Stream m a -> Stream m a
- take :: Monad m => Int -> Stream m a -> Stream m a
- drop :: Monad m => Int -> Stream m a -> Stream m a
- map :: Monad m => (a -> b) -> Stream m a -> Stream m b
- mapM :: Monad m => (a -> m b) -> Stream m a -> Stream m b
- mapM_ :: Monad m => (a -> m b) -> Stream m a -> m ()
- trans :: (Monad m, Monad m') => (forall a. m a -> m' a) -> Stream m a -> Stream m' a
- concatMap :: Monad m => (a -> Stream m b) -> Stream m a -> Stream m b
- zipWith :: Monad m => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
- zipWithM :: Monad m => (a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
- zipWith3 :: Monad m => (a -> b -> c -> d) -> Stream m a -> Stream m b -> Stream m c -> Stream m d
- zipWith3M :: Monad m => (a -> b -> c -> m d) -> Stream m a -> Stream m b -> Stream m c -> Stream m d
- filter :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
- filterM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
- takeWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
- takeWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
- dropWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
- dropWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
- elem :: (Monad m, Eq a) => a -> Stream m a -> m Bool
- notElem :: (Monad m, Eq a) => a -> Stream m a -> m Bool
- find :: Monad m => (a -> Bool) -> Stream m a -> m (Maybe a)
- findM :: Monad m => (a -> m Bool) -> Stream m a -> m (Maybe a)
- findIndex :: Monad m => (a -> Bool) -> Stream m a -> m (Maybe Int)
- findIndexM :: Monad m => (a -> m Bool) -> Stream m a -> m (Maybe Int)
- foldl :: Monad m => (a -> b -> a) -> a -> Stream m b -> m a
- foldlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
- foldM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
- foldl1 :: Monad m => (a -> a -> a) -> Stream m a -> m a
- foldl1M :: Monad m => (a -> a -> m a) -> Stream m a -> m a
- foldl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> m a
- foldlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
- foldl1' :: Monad m => (a -> a -> a) -> Stream m a -> m a
- foldl1M' :: Monad m => (a -> a -> m a) -> Stream m a -> m a
- foldr :: Monad m => (a -> b -> b) -> b -> Stream m a -> m b
- foldrM :: Monad m => (a -> b -> m b) -> b -> Stream m a -> m b
- foldr1 :: Monad m => (a -> a -> a) -> Stream m a -> m a
- foldr1M :: Monad m => (a -> a -> m a) -> Stream m a -> m a
- and :: Monad m => Stream m Bool -> m Bool
- or :: Monad m => Stream m Bool -> m Bool
- concatMapM :: Monad m => (a -> m (Stream m b)) -> Stream m a -> Stream m b
- unfoldr :: Monad m => (s -> Maybe (a, s)) -> s -> Stream m a
- unfoldrM :: Monad m => (s -> m (Maybe (a, s))) -> s -> Stream m a
- prescanl :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
- prescanlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
- prescanl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
- prescanlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
- toList :: Monad m => Stream m a -> m [a]
- fromList :: Monad m => [a] -> Stream m a

# Documentation

Monadic streams

Result of taking a single step in a stream

# Size hints

# Length

# Construction

# Accessing elements

# Substreams

Extract a substream of the given length starting at the given position.

# Mapping

mapM_ :: Monad m => (a -> m b) -> Stream m a -> m ()Source

Execute a monadic action for each element of the `Stream`

trans :: (Monad m, Monad m') => (forall a. m a -> m' a) -> Stream m a -> Stream m' aSource

Transform a `Stream`

to use a different monad

# Zipping

zipWith :: Monad m => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m cSource

Zip two `Stream`

s with the given function

zipWithM :: Monad m => (a -> b -> m c) -> Stream m a -> Stream m b -> Stream m cSource

Zip two `Stream`

s with the given monadic function

zipWith3 :: Monad m => (a -> b -> c -> d) -> Stream m a -> Stream m b -> Stream m c -> Stream m dSource

Zip three `Stream`

s with the given function

zipWith3M :: Monad m => (a -> b -> c -> m d) -> Stream m a -> Stream m b -> Stream m c -> Stream m dSource

Zip three `Stream`

s with the given monadic function

# Filtering

filter :: Monad m => (a -> Bool) -> Stream m a -> Stream m aSource

Drop elements which do not satisfy the predicate

filterM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m aSource

Drop elements which do not satisfy the monadic predicate

takeWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m aSource

Longest prefix of elements that satisfy the predicate

takeWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m aSource

Longest prefix of elements that satisfy the monadic predicate

dropWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m aSource

Drop the longest prefix of elements that satisfy the predicate

dropWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m aSource

Drop the longest prefix of elements that satisfy the monadic predicate

# Searching

elem :: (Monad m, Eq a) => a -> Stream m a -> m BoolSource

Check whether the `Stream`

contains an element

# Folding

foldlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m aSource

Left fold with a monadic operator

foldl1M :: Monad m => (a -> a -> m a) -> Stream m a -> m aSource

Left fold over a non-empty `Stream`

with a monadic operator

foldl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> m aSource

Left fold with a strict accumulator

foldlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m aSource

Left fold with a strict accumulator and a monadic operator

foldl1' :: Monad m => (a -> a -> a) -> Stream m a -> m aSource

Left fold over a non-empty `Stream`

with a strict accumulator

foldl1M' :: Monad m => (a -> a -> m a) -> Stream m a -> m aSource

Left fold over a non-empty `Stream`

with a strict accumulator and a
monadic operator

foldrM :: Monad m => (a -> b -> m b) -> b -> Stream m a -> m bSource

Right fold with a monadic operator

foldr1M :: Monad m => (a -> a -> m a) -> Stream m a -> m aSource

Right fold over a non-empty stream with a monadic operator

# Specialised folds

# Unfolding

unfoldrM :: Monad m => (s -> m (Maybe (a, s))) -> s -> Stream m aSource

Unfold with a monadic function

# Scans

prescanlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m aSource

Prefix scan with a monadic operator

prescanl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m aSource

Prefix scan with strict accumulator

prescanlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m aSource

Prefix scan with strict accumulator and a monadic operator