Copyright | (c) 2020 Composewell Technologies and Contributors (c) Roman Leshchinskiy 2008-2010 |
---|---|
License | BSD-3-Clause |
Maintainer | streamly@composewell.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Prefer unfolds (Streamly.Internal.Data.Unfold) over the combinators in this module. They are more powerful and efficient as they can be transformed and composed on the input side efficiently and they can fuse in nested operations (e.g. unfoldMany). All the combinators in this module can be expressed using unfolds with the same efficiency.
Operations in this module that are not in Streamly.Internal.Data.Unfold: generate, times, fromPrimIORef.
We should plan to replace this module with Streamly.Internal.Data.Unfold in future.
Synopsis
- nil :: Monad m => Stream m a
- nilM :: Applicative m => m b -> Stream m a
- cons :: Monad m => a -> Stream m a -> Stream m a
- consM :: Applicative m => m a -> Stream m a -> Stream m a
- unfold :: Applicative m => Unfold m a b -> 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
- fromPure :: Applicative m => a -> Stream m a
- fromEffect :: Applicative m => m a -> Stream m a
- repeat :: Monad m => a -> Stream m a
- repeatM :: Monad m => m a -> Stream m a
- replicate :: Monad m => Int -> a -> Stream m a
- replicateM :: forall m a. Monad m => Int -> m a -> Stream m a
- enumerateFromStepIntegral :: (Integral a, Monad m) => a -> a -> Stream m a
- enumerateFromIntegral :: (Monad m, Integral a, Bounded a) => a -> Stream m a
- enumerateFromThenIntegral :: (Monad m, Integral a, Bounded a) => a -> a -> Stream m a
- enumerateFromToIntegral :: (Monad m, Integral a) => a -> a -> Stream m a
- enumerateFromThenToIntegral :: (Monad m, Integral a) => a -> a -> a -> Stream m a
- enumerateFromStepNum :: (Monad m, Num a) => a -> a -> Stream m a
- enumerateFromNum :: (Monad m, Num a) => a -> Stream m a
- enumerateFromThenNum :: (Monad m, Num a) => a -> a -> Stream m a
- enumerateFromToFractional :: (Monad m, Fractional a, Ord a) => a -> a -> Stream m a
- enumerateFromThenToFractional :: (Monad m, Fractional a, Ord a) => a -> a -> a -> Stream m a
- times :: MonadIO m => Double -> Stream m (AbsTime, RelTime64)
- fromIndices :: Monad m => (Int -> a) -> Stream m a
- fromIndicesM :: Monad m => (Int -> m a) -> Stream m a
- generate :: Monad m => Int -> (Int -> a) -> Stream m a
- generateM :: Monad m => Int -> (Int -> m a) -> Stream m a
- iterate :: Monad m => (a -> a) -> a -> Stream m a
- iterateM :: Monad m => (a -> m a) -> m a -> Stream m a
- fromList :: Applicative m => [a] -> Stream m a
- fromListM :: MonadAsync m => [m a] -> Stream m a
- fromStreamK :: Applicative m => Stream m a -> Stream m a
- toStreamK :: Monad m => Stream m a -> Stream m a
Primitives
From Unfold
Unfolding
From Values
fromEffect :: Applicative m => m a -> Stream m a Source #
Create a singleton Stream
from a monadic action.
Enumeration
enumerateFromStepIntegral :: (Integral a, Monad m) => a -> a -> Stream m a Source #
Can be used to enumerate unbounded integrals. This does not check for overflow or underflow for bounded integrals.
enumerateFromToIntegral :: (Monad m, Integral a) => a -> a -> Stream m a Source #
Enumerate upwards from from
to to
. We are assuming that "to" is
constrained by the type to be within max/min bounds.
enumerateFromStepNum :: (Monad m, Num a) => a -> a -> Stream m a Source #
For floating point numbers if the increment is less than the precision then it just gets lost. Therefore we cannot always increment it correctly by just repeated addition. 9007199254740992 + 1 + 1 :: Double => 9.007199254740992e15 9007199254740992 + 2 :: Double => 9.007199254740994e15
Instead we accumulate the increment counter and compute the increment every time before adding it to the starting number.
This works for Integrals as well as floating point numbers, but enumerateFromStepIntegral is faster for integrals.
enumerateFromToFractional :: (Monad m, Fractional a, Ord a) => a -> a -> Stream m a Source #
We cannot write a general function for Num. The only way to write code
portable between the two is to use a Real
constraint and convert between
Fractional and Integral using fromRational which is horribly slow.
enumerateFromThenToFractional :: (Monad m, Fractional a, Ord a) => a -> a -> a -> Stream m a Source #
Time Enumeration
From Generators
Generate a monadic stream from a seed.
Iteration
From Containers
Transform an input structure into a stream.
fromListM :: MonadAsync m => [m a] -> Stream m a Source #
Convert a list of monadic actions to a Stream
Conversions
fromStreamK :: Applicative m => Stream m a -> Stream m a Source #
Convert a CPS encoded StreamK to direct style step encoded StreamD