streamly-0.8.0: Dataflow programming and declarative concurrency
Copyright(c) 2020 Composewell Technologies and Contributors
(c) Roman Leshchinskiy 2008-2010
LicenseBSD-3-Clause
Maintainerstreamly@composewell.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Streamly.Internal.Data.Stream.StreamD.Generate

Description

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

Primitives

nil :: Monad m => Stream m a Source #

An empty Stream.

nilM :: Monad m => m b -> Stream m a Source #

An empty Stream with a side effect.

cons :: Monad m => a -> Stream m a -> Stream m a Source #

Can fuse but has O(n^2) complexity.

consM :: Monad m => m a -> Stream m a -> Stream m a Source #

From Unfold

unfold :: Monad m => Unfold m a b -> a -> Stream m b Source #

Convert an Unfold into a Stream by supplying it a seed.

Unfolding

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

unfoldrM :: Monad m => (s -> m (Maybe (a, s))) -> s -> Stream m a Source #

From Values

fromPure :: Applicative m => a -> Stream m a Source #

Create a singleton Stream from a pure value.

fromEffect :: Monad m => m a -> Stream m a Source #

Create a singleton Stream from a monadic action.

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

repeatM :: Monad m => m a -> Stream m a Source #

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

replicateM :: forall m a. Monad m => Int -> m a -> Stream m a Source #

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.

enumerateFromThenToIntegral :: (Monad m, Integral a) => a -> a -> a -> Stream m a Source #

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.

numFrom :: (Monad m, Num a) => a -> Stream m a Source #

numFromThen :: (Monad m, Num a) => a -> a -> Stream m a Source #

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.

fromIndices :: Monad m => (Int -> a) -> Stream m a Source #

fromIndicesM :: Monad m => (Int -> m a) -> Stream m a Source #

generate :: Monad m => Int -> (Int -> a) -> Stream m a Source #

generateM :: Monad m => Int -> (Int -> m a) -> Stream m a Source #

Iteration

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

iterateM :: Monad m => (a -> m a) -> m a -> Stream m a Source #

From Containers

Transform an input structure into a stream.

fromList :: Applicative m => [a] -> Stream m a Source #

Convert a list of pure values to a Stream

fromListM :: MonadAsync m => [m a] -> Stream m a Source #

Convert a list of monadic actions to a Stream

Conversions

fromStreamK :: Monad m => Stream m a -> Stream m a Source #

Convert a CPS encoded StreamK to direct style step encoded StreamD

toStreamK :: Monad m => Stream m a -> Stream m a Source #

Convert a direct style step encoded StreamD to a CPS encoded StreamK

fromStreamD :: (IsStream t, Monad m) => Stream m a -> t m a Source #

toStreamD :: (IsStream t, Monad m) => t m a -> Stream m a Source #