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 for various reasons. 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
- mapM :: (Functor m, Monad m) => (a -> m b) -> Stream m a -> Stream m b
- mapM_ :: (Functor m, Monad m) => (a -> m b) -> Stream m a -> Stream m ()
- reverse :: (Functor m, Monad m) => Stream m a -> m (Stream m a)
- intersperse :: (Functor m, Monad m) => a -> Stream m a -> Stream m a
- intercalate :: (Functor m, Monad m) => Stream 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 ()
- concat :: (Functor m, Monad m) => Stream m [a] -> Stream m a
- concatMap :: (Functor m, Monad m) => (a -> Stream m b) -> Stream m a -> Stream m b
- and :: (Functor m, Monad m) => Stream m Bool -> m Bool
- or :: (Functor m, Monad m) => Stream m Bool -> m Bool
- any :: Monad m => (a -> Bool) -> Stream m a -> m Bool
- all :: Monad m => (a -> Bool) -> Stream m a -> m Bool
- sum :: (Num a, Monad m) => Stream m a -> m a
- product :: (Num a, Monad m) => Stream m a -> m a
- scanl :: (Functor m, Monad m) => (b -> a -> b) -> 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
- take :: (Functor m, Monad m) => Int -> Stream m a -> Stream m a
- drop :: (Functor m, Monad m) => Int -> Stream m a -> Stream m a
- splitAt :: (Functor m, Monad m) => Int -> Stream m a -> (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
- span :: (Functor m, Monad m) => (a -> Bool) -> Stream m a -> (Stream m a, Stream m a)
- break :: (Functor m, Monad m) => (a -> Bool) -> Stream m a -> (Stream m a, Stream m a)
- isPrefixOf :: (Eq a, Monad m) => Stream m a -> Stream m a -> m Bool
- isSuffixOf :: (Eq a, Functor m, Monad m) => Stream m a -> Stream m a -> m Bool
- elem :: (Eq a, Monad m) => a -> Stream m a -> m Bool
- notElem :: (Eq a, Monad m) => a -> Stream m a -> m Bool
- lookup :: (Eq a, Monad m) => a -> Stream m (a, b) -> m (Maybe b)
- find :: Monad m => (a -> Bool) -> Stream m a -> m (Maybe a)
- filter :: 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)
- zip3 :: (Functor m, Applicative m, Monad m) => Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
- zip4 :: (Functor m, Applicative m, Monad m) => Stream m a -> Stream m b -> Stream m c -> Stream m d -> Stream m (a, b, c, d)
- zipWith :: (Functor m, Applicative m, Monad m) => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
- zipWith3 :: (Functor m, Applicative m, Monad m) => (a -> b -> c -> d) -> Stream m a -> Stream m b -> Stream m c -> Stream m d
- zipWith4 :: (Functor m, Applicative m, Monad m) => (a -> b -> c -> d -> e) -> Stream m a -> Stream m b -> Stream m c -> Stream m d -> Stream m e
- unzip :: (Functor m, Monad m) => Stream m (a, b) -> m ([a], [b])
- unzip3 :: (Functor m, Monad m) => Stream m (a, b, c) -> m ([a], [b], [c])
- unzip4 :: (Functor m, Monad m) => Stream m (a, b, c, d) -> m ([a], [b], [c], [d])
- delete :: (Eq a, Functor m, Monad m) => a -> Stream m a -> Stream m a
- insert :: (Ord a, Functor m, Monad m) => a -> Stream m a -> Stream m a
- deleteBy :: (Functor m, Monad m) => (a -> a -> Bool) -> a -> Stream m a -> Stream m a
- insertBy :: (Functor m, Monad m) => (a -> a -> Ordering) -> a -> Stream m a -> Stream m a
- genericLength :: (Num i, Functor m, Monad m) => Stream m a -> m i
- genericTake :: (Integral i, Functor m, Monad m) => i -> Stream m a -> Stream m a
- genericDrop :: (Integral i, Functor m, Monad m) => i -> Stream m a -> Stream m a
- genericSplitAt :: (Integral i, Functor m, Monad m) => i -> Stream m a -> (Stream m a, Stream m a)
- genericReplicate :: (Integral i, Functor m, Monad m) => i -> a -> Stream m a
- enumFromToInt :: Monad m => Int -> Int -> Stream m Int
- enumFromToChar :: Monad m => Char -> Char -> Stream m Char
- enumDeltaInteger :: Monad m => Integer -> Integer -> Stream m Integer

# Documentation

# Conversion with lists

# Basic functions

# Transformations

# Folds

# Special folds

# Building streams

## Scans

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

# Substreams

## Extracting substreams

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

splitAt n s = (take n s, drop n s)

Note that the resulting `Streams`

share their state, so do not interleave
traversals.

## Predicates

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

Note that this is:

isSuffixOf a b = reverse a `isPrefixOf` reverse b

It might be more efficient to construct the `Stream`

s in reverse order and
use `isPrefixOf`

directly, as `reverse`

is *O(n)* and requires a finite
stream argument.

# Searching streams

## Searching by equality

## Searching with a predicate

# Zipping and unzipping

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

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

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

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

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

# Special streams

## "Set" operations

# Generalized functions

## User-supplied comparison, replacing an Ord context

# The "generic" operations

genericSplitAt :: (Integral i, Functor m, Monad m) => i -> Stream m a -> (Stream m a, Stream m a) Source

enumFromToInt :: Monad m => Int -> Int -> Stream m Int Source

Like `fromList ([n..m] :: [Int])`

but avoids allocating a list