Copyright | (c) 2017 Harendra Kumar |
---|---|
License | BSD3 |
Maintainer | harendra.kumar@gmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
- nil :: Streaming t => t m a
- cons :: Streaming t => a -> t m a -> t m a
- (.:) :: Streaming t => a -> t m a -> t m a
- unfoldr :: Streaming t => (b -> Maybe (a, b)) -> b -> t m a
- unfoldrM :: (Streaming t, Monad m) => (b -> m (Maybe (a, b))) -> b -> t m a
- each :: (Streaming t, Foldable f) => f a -> t m a
- iterate :: Streaming t => (a -> a) -> a -> t m a
- iterateM :: (Streaming t, Monad m) => (a -> m a) -> a -> t m a
- foldr :: (Streaming t, Monad m) => (a -> b -> b) -> b -> t m a -> m b
- foldrM :: Streaming t => (a -> m b -> m b) -> m b -> t m a -> m b
- scan :: Streaming t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b
- foldl :: (Streaming t, Monad m) => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
- foldlM :: (Streaming t, Monad m) => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b
- uncons :: (Streaming t, Monad m) => t m a -> m (Maybe (a, t m a))
- toList :: (Streaming t, Monad m) => t m a -> m [a]
- all :: (Streaming t, Monad m) => (a -> Bool) -> t m a -> m Bool
- any :: (Streaming t, Monad m) => (a -> Bool) -> t m a -> m Bool
- head :: (Streaming t, Monad m) => t m a -> m (Maybe a)
- tail :: (Streaming t, Monad m) => t m a -> m (Maybe (t m a))
- last :: (Streaming t, Monad m) => t m a -> m (Maybe a)
- null :: (Streaming t, Monad m) => t m a -> m Bool
- length :: (Streaming t, Monad m) => t m a -> m Int
- elem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool
- notElem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool
- reverse :: Streaming t => t m a -> t m a
- maximum :: (Streaming t, Monad m, Ord a) => t m a -> m (Maybe a)
- minimum :: (Streaming t, Monad m, Ord a) => t m a -> m (Maybe a)
- sum :: (Streaming t, Monad m, Num a) => t m a -> m a
- product :: (Streaming t, Monad m, Num a) => t m a -> m a
- filter :: Streaming t => (a -> Bool) -> t m a -> t m a
- take :: Streaming t => Int -> t m a -> t m a
- takeWhile :: Streaming t => (a -> Bool) -> t m a -> t m a
- drop :: Streaming t => Int -> t m a -> t m a
- dropWhile :: Streaming t => (a -> Bool) -> t m a -> t m a
- mapM :: (Streaming t, Monad m) => (a -> m b) -> t m a -> t m b
- mapM_ :: (Streaming t, Monad m) => (a -> m b) -> t m a -> m ()
- sequence :: (Streaming t, Monad m) => t m (m a) -> t m a
- replicateM :: (Streaming t, Monad m) => Int -> m a -> t m a
- zipWith :: Streaming t => (a -> b -> c) -> t m a -> t m b -> t m c
- zipWithM :: Streaming t => (a -> b -> t m c) -> t m a -> t m b -> t m c
- zipAsyncWith :: (Streaming t, MonadAsync m) => (a -> b -> c) -> t m a -> t m b -> t m c
- zipAsyncWithM :: (Streaming t, MonadAsync m) => (a -> b -> t m c) -> t m a -> t m b -> t m c
- fromHandle :: (Streaming t, MonadIO m) => Handle -> t m String
- toHandle :: (Streaming t, MonadIO m) => Handle -> t m String -> m ()
Construction
nil :: Streaming t => t m a Source #
Represesnts an empty stream just like []
represents an empty list.
cons :: Streaming t => a -> t m a -> t m a infixr 5 Source #
Constructs a stream by adding a pure value at the head of an existing
stream, just like :
constructs lists. For example:
> let stream = 1 `cons` 2 `cons` 3 `cons` nil > (toList . serially) stream [1,2,3]
(.:) :: Streaming t => a -> t m a -> t m a infixr 5 Source #
Operator equivalent of cons
so that you can construct a stream of pure
values more succinctly like this:
> let stream = 1 .: 2 .: 3 .: nil > (toList . serially) stream [1,2,3]
.:
constructs a stream just like :
constructs a list.
Also note that another equivalent way of building streams from pure values is:
> let stream = pure 1 <> pure 2 <> pure 3 > (toList . serially) stream [1,2,3]
In the first method we construct a stream by adding one element at a time.
In the second method we first construct singleton streams using pure
and
then compose all those streams together using the Semigroup
style
composition of streams. The former method is a bit more efficient than the
latter.
unfoldr :: Streaming t => (b -> Maybe (a, b)) -> b -> t m a Source #
Build a Stream by unfolding pure steps starting from a seed.
unfoldrM :: (Streaming t, Monad m) => (b -> m (Maybe (a, b))) -> b -> t m a Source #
Build a Stream by unfolding monadic steps starting from a seed.
iterate :: Streaming t => (a -> a) -> a -> t m a Source #
Iterate a pure function from a seed value, streaming the results forever
iterateM :: (Streaming t, Monad m) => (a -> m a) -> a -> t m a Source #
Iterate a monadic function from a seed value, streaming the results forever
Elimination
General Folds
foldrM :: Streaming t => (a -> m b -> m b) -> m b -> t m a -> m b Source #
Right fold with a monadic step function. See toList
for an example use.
scan :: Streaming t => (x -> a -> x) -> x -> (x -> b) -> t m a -> t m b Source #
Scan left. A strict left fold which accumulates the result of its reduction steps inside a stream, from left.
foldl :: (Streaming t, Monad m) => (x -> a -> x) -> x -> (x -> b) -> t m a -> m b Source #
Strict left fold. This is typed to work with the foldl package. To use
it normally just pass id
as the third argument.
foldlM :: (Streaming t, Monad m) => (x -> a -> m x) -> m x -> (x -> m b) -> t m a -> m b Source #
Strict left fold, with monadic step function. This is typed to work
with the foldl package. To use directly pass id
as the third argument.
uncons :: (Streaming t, Monad m) => t m a -> m (Maybe (a, t m a)) Source #
Decompose a stream into its head and tail. If the stream is empty, returns
Nothing
. If the stream is non-empty, returns 'Just (a, ma)', where a
is
the head of the stream and ma
its tail.
Special Folds
toList :: (Streaming t, Monad m) => t m a -> m [a] Source #
Convert a stream into a list in the underlying monad.
all :: (Streaming t, Monad m) => (a -> Bool) -> t m a -> m Bool Source #
Determine whether all elements of a stream satisfy a predicate.
any :: (Streaming t, Monad m) => (a -> Bool) -> t m a -> m Bool Source #
Determine whether any of the elements of a stream satisfy a predicate.
head :: (Streaming t, Monad m) => t m a -> m (Maybe a) Source #
Extract the first element of the stream, if any.
tail :: (Streaming t, Monad m) => t m a -> m (Maybe (t m a)) Source #
Extract all but the first element of the stream, if any.
last :: (Streaming t, Monad m) => t m a -> m (Maybe a) Source #
Extract the last element of the stream, if any.
elem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool Source #
Determine whether an element is present in the stream.
notElem :: (Streaming t, Monad m, Eq a) => a -> t m a -> m Bool Source #
Determine whether an element is not present in the stream.
reverse :: Streaming t => t m a -> t m a Source #
Returns the elements of the stream in reverse order. The stream must be finite.
maximum :: (Streaming t, Monad m, Ord a) => t m a -> m (Maybe a) Source #
Determine the maximum element in a stream.
minimum :: (Streaming t, Monad m, Ord a) => t m a -> m (Maybe a) Source #
Determine the minimum element in a stream.
sum :: (Streaming t, Monad m, Num a) => t m a -> m a Source #
Determine the sum of all elements of a stream of numbers
product :: (Streaming t, Monad m, Num a) => t m a -> m a Source #
Determine the product of all elements of a stream of numbers
Filtering
filter :: Streaming t => (a -> Bool) -> t m a -> t m a Source #
Include only those elements that pass a predicate.
take :: Streaming t => Int -> t m a -> t m a Source #
Take first n
elements from the stream and discard the rest.
takeWhile :: Streaming t => (a -> Bool) -> t m a -> t m a Source #
End the stream as soon as the predicate fails on an element.
drop :: Streaming t => Int -> t m a -> t m a Source #
Discard first n
elements from the stream and take the rest.
dropWhile :: Streaming t => (a -> Bool) -> t m a -> t m a Source #
Drop elements in the stream as long as the predicate succeeds and then take the rest of the stream.
Transformation
mapM :: (Streaming t, Monad m) => (a -> m b) -> t m a -> t m b Source #
Replace each element of the stream with the result of a monadic action applied on the element.
mapM_ :: (Streaming t, Monad m) => (a -> m b) -> t m a -> m () Source #
Apply a monadic action to each element of the stream and discard the output of the action.
sequence :: (Streaming t, Monad m) => t m (m a) -> t m a Source #
Reduce a stream of monadic actions to a stream of the output of those actions.
replicateM :: (Streaming t, Monad m) => Int -> m a -> t m a Source #
Generate a stream by performing an action n
times.
Zipping
zipWith :: Streaming t => (a -> b -> c) -> t m a -> t m b -> t m c Source #
Zip two streams serially using a pure zipping function.
zipWithM :: Streaming t => (a -> b -> t m c) -> t m a -> t m b -> t m c Source #
Zip two streams serially using a monadic zipping function.
zipAsyncWith :: (Streaming t, MonadAsync m) => (a -> b -> c) -> t m a -> t m b -> t m c Source #
Zip two streams asyncly (i.e. both the elements being zipped are generated concurrently) using a pure zipping function.
zipAsyncWithM :: (Streaming t, MonadAsync m) => (a -> b -> t m c) -> t m a -> t m b -> t m c Source #
Zip two streams asyncly (i.e. both the elements being zipped are generated concurrently) using a monadic zipping function.