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

Modulestreamly-0.10.1Haskell2010

Streamly.Internal.Data.Stream.Serial

Deprecated. Please use Streamly.Internal.Data.Stream from streamly-core package instead.

To run examples in this module:

Example1 expression
import qualified Streamly.Prelude as Stream
  • 4 types
  • 13 values
  • Packagestreamly-0.10.1
  • Exports19
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceSerial.hs

Serial appending stream

5 declarations
newtypenewtype SerialT (m :: Type -> Type) a
#

For SerialT streams:

(<>) = Streamly.Prelude.serial                       -- Semigroup
(>>=) = flip . Streamly.Prelude.concatMapWith Streamly.Prelude.serial -- Monad

A single Monad bind behaves like a for loop:

Example1 expression
:{IsStream.toList $ do     x <- IsStream.fromList [1,2] -- foreach x in stream     return x:}[1,2]

Nested monad binds behave like nested for loops:

Example1 expression
:{IsStream.toList $ do    x <- IsStream.fromList [1,2] -- foreach x in stream    y <- IsStream.fromList [3,4] -- foreach y in stream    return (x, y):}[(1,3),(1,4),(2,3),(2,4)]

Since: 0.2.0 (Streamly)

Constructors

Instances22MonadTrans, IsStream, MonadReader, MonadState, Monad, Functor, …
typetype Serial = SerialT IO
#

A serial IO stream of elements of type a. See SerialT documentation for more details.

Since: 0.2.0 (Streamly)

Serial interleaving stream

6 declarations
newtypenewtype WSerialT (m :: Type -> Type) a
#

For WSerialT streams:

(<>) = Streamly.Prelude.wSerial                       -- Semigroup
(>>=) = flip . Streamly.Prelude.concatMapWith Streamly.Prelude.wSerial -- Monad

Note that <> is associative only if we disregard the ordering of elements in the resulting stream.

A single Monad bind behaves like a for loop:

Example1 expression
:{IsStream.toList $ IsStream.fromWSerial $ do     x <- IsStream.fromList [1,2] -- foreach x in stream     return x:}[1,2]

Nested monad binds behave like interleaved nested for loops:

Example1 expression
:{IsStream.toList $ IsStream.fromWSerial $ do    x <- IsStream.fromList [1,2] -- foreach x in stream    y <- IsStream.fromList [3,4] -- foreach y in stream    return (x, y):}[(1,3),(2,3),(1,4),(2,4)]

It is a result of interleaving all the nested iterations corresponding to element 1 in the first stream with all the nested iterations of element 2:

Example2 expressions
import Streamly.Prelude (wSerial)IsStream.toList $ IsStream.fromList [(1,3),(1,4)] `IsStream.wSerial` IsStream.fromList [(2,3),(2,4)][(1,3),(2,3),(1,4),(2,4)]

The W in the name stands for wide or breadth wise scheduling in contrast to the depth wise scheduling behavior of SerialT.

Since: 0.2.0 (Streamly)

Constructors

Instances22MonadTrans, IsStream, MonadReader, MonadState, Monad, Functor, …
typetype WSerial = WSerialT IO
#

An interleaving serial IO stream of elements of type a. See WSerialT documentation for more details.

Since: 0.2.0 (Streamly)

valuewSerial :: WSerialT m a -> WSerialT m a -> WSerialT m a
#

Interleaves two streams, yielding one element from each stream alternately. When one stream stops the rest of the other stream is used in the output stream.

This gives exponential priority to earlier streams than the ones joining later. Because of exponential weighting it can be used with concatMapWith.

Not fused

Construction

5 declarations
valuerepeat :: Monad m => a -> SerialT m a
#

Generate an infinite stream by repeating a pure value.

valueunfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> SerialT m a
#

Build a stream by unfolding a monadic step function starting from a seed. The step function returns the next element in the stream and the next seed value. When it is done it returns Nothing and the stream ends. For example,

let f b =
        if b > 3
        then return Nothing
        else print b >> return (Just (b, b + 1))
in drain $ unfoldrM f 0
 0
 1
 2
 3

Pre-release

methodfromList :: [Item l] -> l
#

The fromList function constructs the structure l from the given list of Item l

Elimination

1 declaration
methodtoList :: l -> [Item l]
#

The toList function extracts a list of Item l from the structure l. It should satisfy fromList . toList = id.

Transformation

2 declarations
valuemap :: Monad m => (a -> b) -> SerialT m a -> SerialT m b
#
map = fmap

Same as fmap.

> S.toList $ S.map (+1) $ S.fromList [1,2,3]
[2,3,4]