Copyright | (c) 2014 Kim Altintop |
---|---|

License | BSD3 |

Maintainer | kim.altintop@gmail.com |

Stability | experimental |

Portability | non-portable |

Safe Haskell | None |

Language | Haskell2010 |

(Mostly mechanical) adaptation of the
Data.Stream
module from the
stream-fusion package to a
monadic `Stream`

datatype similar to the one
proposed by
Michael Snoyman for the conduit
package.

The intention here is to provide a high-level, Data.List-like interface to Database.LevelDB.Iterators with predictable space and time complexity (see Database.LevelDB.Streaming), and without introducing a dependency eg. on one of the streaming libraries (all relevant datatypes are fully exported, though, so it should be straightforward to write wrappers for your favourite streaming library).

Fusion and inlining rules and strictness annotations have been put in place
faithfully, and may need further profiling. Also, some functions (from
Data.List) have been omitted as either no obvious solution exists (notably
`mapM`

), they didn't seem too useful in the given context (eg. `lookup`

), or
I was just too lazy. Missing functions may be added upon
request.

- data Step a s
- data Stream m a = forall s . Stream (s -> m (Step a s)) (m s)
- toList :: (Functor m, Monad m) => Stream m a -> m [a]
- fromList :: Monad m => [a] -> Stream m a
- append :: (Functor m, Monad m) => Stream m a -> Stream m a -> Stream m a
- cons :: (Functor m, Monad m) => a -> Stream m a -> Stream m a
- snoc :: (Functor m, Monad m) => Stream m a -> a -> Stream m a
- head :: Monad m => Stream m a -> m (Maybe a)
- last :: Monad m => Stream m a -> m (Maybe a)
- tail :: (Functor m, Monad m) => Stream m a -> Stream m a
- init :: (Functor m, Monad m) => Stream m a -> Stream m a
- null :: Monad m => Stream m a -> m Bool
- length :: Monad m => Stream m a -> m Int
- map :: Monad m => (a -> b) -> Stream m a -> Stream m b
- intersperse :: (Functor m, Monad m) => a -> Stream m a -> Stream m a
- foldl :: Monad m => (b -> a -> b) -> b -> Stream m a -> m b
- foldl' :: Monad m => (b -> a -> b) -> b -> Stream m a -> m b
- foldr :: (Functor m, Monad m) => (a -> b -> b) -> b -> Stream m a -> m b
- foldMap :: (Monoid m, Functor n, Monad n) => (a -> m) -> Stream n a -> n m
- foldM :: Monad m => (b -> a -> m b) -> b -> Stream m a -> m b
- foldM_ :: Monad m => (b -> a -> m b) -> b -> Stream m a -> m ()
- concatMap :: (Functor m, Monad m) => (a -> Stream m b) -> Stream m a -> Stream m b
- iterate :: Monad m => (a -> a) -> a -> Stream m a
- repeat :: Monad m => a -> Stream m a
- replicate :: Monad m => Int -> a -> Stream m a
- cycle :: (Functor m, Monad m) => Stream m a -> Stream m a
- unfoldr :: Monad m => (b -> Maybe (a, b)) -> b -> Stream m a
- unfoldrM :: (Functor m, Monad m) => (b -> Maybe (a, m b)) -> m b -> Stream m a
- filter :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
- take :: (Functor m, Monad m) => Int -> Stream m a -> Stream m a
- drop :: (Functor m, Monad m) => Int -> Stream m a -> Stream m a
- takeWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
- dropWhile :: (Functor m, Monad m) => (a -> Bool) -> Stream m a -> Stream m a
- zip :: (Functor m, Applicative m, Monad m) => Stream m a -> Stream m b -> Stream m (a, b)
- zipWith :: (Functor m, Applicative m, Monad m) => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
- unzip :: (Functor m, Monad m) => Stream m (a, b) -> m ([a], [b])

# Documentation

# Conversion with lists

# Basic functions

# Transformations

# Folds

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

Left-associative fold.

Note that the *direction* of the traversal is not defined here.

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

Left-associative fold with strict accumulator.

Note that the *direction* of the traversal is not defined here.

foldr :: (Functor m, Monad m) => (a -> b -> b) -> b -> Stream m a -> m b Source

Right-associative fold.

Note that the *direction* of the traversal is not defined here.

# Special folds

# Infinite streams

# Unfolding

unfoldrM :: (Functor m, Monad m) => (b -> Maybe (a, m b)) -> m b -> Stream m a Source

Build a stream from a monadic seed (or state function).