leveldb-haskell-0.4.0: Haskell bindings to LevelDB

Copyright(c) 2014 Kim Altintop
LicenseBSD3
Maintainerkim.altintop@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Stream.Monadic

Contents

Description

(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.

Synopsis

Documentation

data Step a s Source

Constructors

Yield a !s 
Skip !s 
Done 

data Stream m a Source

Constructors

forall s . Stream (s -> m (Step a s)) (m s) 

Instances

Monad m => Functor (Stream m) 

Conversion with lists

toList :: (Functor m, Monad m) => Stream m a -> m [a] Source

fromList :: Monad m => [a] -> Stream m a Source

Basic functions

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

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

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

head :: Monad m => Stream m a -> m (Maybe a) Source

Unlike head, this function does not diverge if the 'Stream is empty. Instead, Nothing is returned.

last :: Monad m => Stream m a -> m (Maybe a) Source

Unlike last, this function does not diverge if the Stream is empty. Instead, Nothing is returned.

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

Unlike tail, this function does not diverge if the Stream is empty. Instead, it is the identity in this case.

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

Unlike init, this function does not diverge if the Stream is empty. Instead, it is the identity in this case.

null :: Monad m => Stream m a -> m Bool Source

length :: Monad m => Stream m a -> m Int Source

Transformations

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

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

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.

foldMap :: (Monoid m, Functor n, Monad n) => (a -> m) -> Stream n a -> n m Source

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

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

Special folds

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

Infinite streams

iterate :: Monad m => (a -> a) -> a -> Stream m a Source

repeat :: Monad m => a -> Stream m a Source

replicate :: Monad m => Int -> a -> Stream m a Source

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

Unlike cycle, this function does not diverge if the Stream is empty. Instead, it is the identity in this case.

Unfolding

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

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).

Searching streams

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

Substreams

take :: (Functor m, Monad m) => Int -> Stream m a -> Stream m a Source

drop :: (Functor m, Monad m) => Int -> Stream m a -> Stream m a Source

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

dropWhile :: (Functor m, Monad m) => (a -> Bool) -> Stream m a -> Stream m a Source

Zipping and unzipping

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

zipWith :: (Functor m, Applicative m, Monad m) => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c Source

unzip :: (Functor m, Monad m) => Stream m (a, b) -> m ([a], [b]) Source