HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelinear-base-0.4.0Haskell2010

Streaming.Linear.Internal.Produce

This module provides all functions which produce a 'Stream (Of a) m r' from some given non-stream inputs.

  • 27 values

Constructing Finite Streams

9 declarations
valueyield :: Monad m => a -> Stream (Of a) m ()
#

A singleton stream

>>> stdoutLn $ yield "hello"
hello
>>> S.sum $ do {yield 1; yield 2; yield 3}
6 :> ()
valueeach' :: Monad m => [a] -> Stream (Of a) m ()
#

Stream the elements of a pure, foldable container.

>>> S.print $ each' [1..3]
1
2
3
valueunfoldr
  1. :: Monad m
  2. => s %1 -> m (Either r (Ur a, s))
  3. -> s
  4. -> Stream (Of a) m r
#

Build a Stream by unfolding steps starting from a seed. In particular note that S.unfoldr S.next = id.

valuereadFile :: FilePath -> Stream (Of Text) RIO ()
#

Read the lines of a file given the filename.

valuereplicate :: (HasCallStack, Monad m) => Int -> a -> Stream (Of a) m ()
#

Repeat an element several times.

valuereplicateM :: Monad m => Int -> m (Ur a) -> Stream (Of a) m ()
#

Repeat an action several times, streaming its results.

>>> import qualified Unsafe.Linear as Unsafe
>>> import qualified Data.Time as Time
>>> let getCurrentTime = fromSystemIO (Unsafe.coerce Time.getCurrentTime)
>>> S.print $ S.replicateM 2 getCurrentTime
2015-08-18 00:57:36.124508 UTC
2015-08-18 00:57:36.124785 UTC
valuereplicateZip :: Monad m => Stream (Of x) m r -> a -> Stream (Of (a, x)) m r
#

Replicate a constant element and zip it with the finite stream which is the first argument.

valueuntilRight :: Monad m => m (Either (Ur a) r) -> Stream (Of a) m r
#

Working with infinite Streams

18 declarations
valuestdinLnN :: Int -> Stream (Of Text) IO ()
#

stdinLnN n is a stream of n lines from standard input

valuestdinLnUntil :: (Text -> Bool) -> Stream (Of Text) IO ()
#

Provides a stream of standard input and omits the first line that satisfies the predicate

valuestdinLnUntilM :: (Text -> IO Bool) -> Stream (Of Text) IO ()
#

Provides a stream of standard input and omits the first line that satisfies the predicate, possibly requiring IO

valuestdinLnZip :: Stream (Of x) IO r %1 -> Stream (Of (x, Text)) IO r
#

Given a finite stream, provide a stream of lines of standard input zipped with that finite stream

valuereadLnN :: Read a => Int -> Stream (Of a) IO ()
#
valuereadLnUntil :: Read a => (a -> Bool) -> Stream (Of a) IO ()
#
valuereadLnUntilM :: Read a => (a -> IO Bool) -> Stream (Of a) IO ()
#
valuereadLnZip :: Read a => Stream (Of x) IO r %1 -> Stream (Of (x, a)) IO r
#
valueiterateN :: Monad m => Int -> (a -> a) -> a -> Stream (Of a) m ()
#

Iterate a pure function from a seed value, streaming the results forever.

valueiterateZip
  1. :: Monad m
  2. => Stream (Of x) m r
  3. -> a -> a
  4. -> a
  5. -> Stream (Of (x, a)) m r
#
valueiterateMN
  1. :: Monad m
  2. => Int
  3. -> a -> m (Ur a)
  4. -> m (Ur a)
  5. -> Stream (Of a) m ()
#

Iterate a monadic function from a seed value, streaming the results forever.

valueiterateMZip
  1. :: Monad m
  2. => Stream (Of x) m r
  3. -> a -> m (Ur a)
  4. -> m (Ur a)
  5. -> Stream (Of (x, a)) m r
#
valuecycleN
  1. :: (Monad m, Consumable r)
  2. => Int
  3. -> Stream (Of a) m r
  4. -> Stream (Of a) m r
#

Cycle a stream a finite number of times

valuecycleZip
  1. :: (Monad m, Consumable s)
  2. => Stream (Of a) m r
  3. -> Stream (Of b) m s
  4. -> Stream (Of (a, b)) m (r, s)
#

cycleZip s1 s2 will cycle s2 just enough to zip with the given finite stream s1. Note that we consume all the effects of the remainder of the cycled stream s2. That is, we consume s2 the smallest natural number of times we need to zip.

valueenumFromN :: (Monad m, Enum e) => Int -> e -> Stream (Of e) m ()
#

Like enumFromThenN but where the next element in the enumeration is just the successor succ n for a given enum n.

valueenumFromZip
  1. :: (Monad m, Enum e)
  2. => Stream (Of a) m r
  3. -> e
  4. -> Stream (Of (a, e)) m r
#

Like enumFromThenZip but where the next element in the enumeration is just the successor succ n for a given enum n.

valueenumFromThenN :: (Monad m, Enum e) => Int -> e -> e -> Stream (Of e) m ()
#

An finite sequence of enumerable values at a fixed distance, determined by the first and second values.

>>> S.print $ S.enumFromThenN 3 100 200
100
200
300
valueenumFromThenZip
  1. :: (Monad m, Enum e)
  2. => Stream (Of a) m r
  3. -> e
  4. -> e
  5. -> Stream (Of (a, e)) m r
#

A finite sequence of enumerable values at a fixed distance determined by the first and second values. The length is limited by zipping with a given finite stream, i.e., the first argument.