streamly-0.10.1: Streaming, dataflow programming and declarative concurrency
Copyright(c) 2017 Composewell Technologies
LicenseBSD3
Maintainerstreamly@composewell.com
Stabilityexperimental
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageHaskell2010

Streamly.Internal.Data.Stream.Serial

Description

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

To run examples in this module:

>>> import qualified Streamly.Prelude as Stream
Synopsis

Serial appending stream

newtype SerialT m a Source #

For SerialT streams:

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

A single Monad bind behaves like a for loop:

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

Nested monad binds behave like nested for loops:

>>> :{
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)

Since: 0.8.0

Constructors

SerialT 

Fields

Instances

Instances details
IsStream SerialT Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.IsStream.Type

Methods

toStream :: forall (m :: Type -> Type) a. SerialT m a -> StreamK m a

fromStream :: forall (m :: Type -> Type) a. StreamK m a -> SerialT m a

consM :: MonadAsync m => m a -> SerialT m a -> SerialT m a Source #

(|:) :: MonadAsync m => m a -> SerialT m a -> SerialT m a Source #

MonadTrans SerialT Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

lift :: Monad m => m a -> SerialT m a Source #

MonadReader r m => MonadReader r (SerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

ask :: SerialT m r Source #

local :: (r -> r) -> SerialT m a -> SerialT m a Source #

reader :: (r -> a) -> SerialT m a Source #

MonadState s m => MonadState s (SerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

get :: SerialT m s Source #

put :: s -> SerialT m () Source #

state :: (s -> (a, s)) -> SerialT m a Source #

(MonadBase b m, Monad m) => MonadBase b (SerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

liftBase :: b α -> SerialT m α Source #

MonadIO m => MonadIO (SerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

liftIO :: IO a -> SerialT m a Source #

(Foldable m, Monad m) => Foldable (SerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

fold :: Monoid m0 => SerialT m m0 -> m0 Source #

foldMap :: Monoid m0 => (a -> m0) -> SerialT m a -> m0 Source #

foldMap' :: Monoid m0 => (a -> m0) -> SerialT m a -> m0 Source #

foldr :: (a -> b -> b) -> b -> SerialT m a -> b Source #

foldr' :: (a -> b -> b) -> b -> SerialT m a -> b Source #

foldl :: (b -> a -> b) -> b -> SerialT m a -> b Source #

foldl' :: (b -> a -> b) -> b -> SerialT m a -> b Source #

foldr1 :: (a -> a -> a) -> SerialT m a -> a Source #

foldl1 :: (a -> a -> a) -> SerialT m a -> a Source #

toList :: SerialT m a -> [a] Source #

null :: SerialT m a -> Bool Source #

length :: SerialT m a -> Int Source #

elem :: Eq a => a -> SerialT m a -> Bool Source #

maximum :: Ord a => SerialT m a -> a Source #

minimum :: Ord a => SerialT m a -> a Source #

sum :: Num a => SerialT m a -> a Source #

product :: Num a => SerialT m a -> a Source #

Traversable (SerialT Identity) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

traverse :: Applicative f => (a -> f b) -> SerialT Identity a -> f (SerialT Identity b) Source #

sequenceA :: Applicative f => SerialT Identity (f a) -> f (SerialT Identity a) Source #

mapM :: Monad m => (a -> m b) -> SerialT Identity a -> m (SerialT Identity b) Source #

sequence :: Monad m => SerialT Identity (m a) -> m (SerialT Identity a) Source #

Monad m => Applicative (SerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

pure :: a -> SerialT m a Source #

(<*>) :: SerialT m (a -> b) -> SerialT m a -> SerialT m b Source #

liftA2 :: (a -> b -> c) -> SerialT m a -> SerialT m b -> SerialT m c Source #

(*>) :: SerialT m a -> SerialT m b -> SerialT m b Source #

(<*) :: SerialT m a -> SerialT m b -> SerialT m a Source #

Monad m => Functor (SerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

fmap :: (a -> b) -> SerialT m a -> SerialT m b Source #

(<$) :: a -> SerialT m b -> SerialT m a Source #

Monad m => Monad (SerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

(>>=) :: SerialT m a -> (a -> SerialT m b) -> SerialT m b Source #

(>>) :: SerialT m a -> SerialT m b -> SerialT m b Source #

return :: a -> SerialT m a Source #

NFData1 (SerialT Identity) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

liftRnf :: (a -> ()) -> SerialT Identity a -> () Source #

MonadThrow m => MonadThrow (SerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

throwM :: Exception e => e -> SerialT m a Source #

a ~ Char => IsString (SerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Monoid (SerialT m a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

mempty :: SerialT m a Source #

mappend :: SerialT m a -> SerialT m a -> SerialT m a Source #

mconcat :: [SerialT m a] -> SerialT m a Source #

Semigroup (SerialT m a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

(<>) :: SerialT m a -> SerialT m a -> SerialT m a Source #

sconcat :: NonEmpty (SerialT m a) -> SerialT m a Source #

stimes :: Integral b => b -> SerialT m a -> SerialT m a Source #

IsList (SerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Associated Types

type Item (SerialT Identity a) Source #

Read a => Read (SerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Show a => Show (SerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

NFData a => NFData (SerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

rnf :: SerialT Identity a -> () Source #

Eq a => Eq (SerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Ord a => Ord (SerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

type Item (SerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

type Item (SerialT Identity a) = a

toStreamK :: SerialT m a -> Stream m a Source #

fromStreamK :: Stream m a -> SerialT m a Source #

type Serial = SerialT IO Source #

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

Since: 0.2.0 (Streamly)

Since: 0.8.0

serial :: SerialT m a -> SerialT m a -> SerialT m a Source #

Serial interleaving stream

newtype WSerialT m a Source #

For WSerialT streams:

(<>) = wSerial                       -- Semigroup
(>>=) = flip . concatMapWith 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:

>>> :{
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:

>>> :{
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:

>>> 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)

Since: 0.8.0

Constructors

WSerialT 

Fields

Instances

Instances details
IsStream WSerialT Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.IsStream.Type

Methods

toStream :: forall (m :: Type -> Type) a. WSerialT m a -> StreamK m a

fromStream :: forall (m :: Type -> Type) a. StreamK m a -> WSerialT m a

consM :: MonadAsync m => m a -> WSerialT m a -> WSerialT m a Source #

(|:) :: MonadAsync m => m a -> WSerialT m a -> WSerialT m a Source #

MonadTrans WSerialT Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

lift :: Monad m => m a -> WSerialT m a Source #

MonadReader r m => MonadReader r (WSerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

ask :: WSerialT m r Source #

local :: (r -> r) -> WSerialT m a -> WSerialT m a Source #

reader :: (r -> a) -> WSerialT m a Source #

MonadState s m => MonadState s (WSerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

get :: WSerialT m s Source #

put :: s -> WSerialT m () Source #

state :: (s -> (a, s)) -> WSerialT m a Source #

MonadIO m => MonadIO (WSerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

liftIO :: IO a -> WSerialT m a Source #

(Foldable m, Monad m) => Foldable (WSerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

fold :: Monoid m0 => WSerialT m m0 -> m0 Source #

foldMap :: Monoid m0 => (a -> m0) -> WSerialT m a -> m0 Source #

foldMap' :: Monoid m0 => (a -> m0) -> WSerialT m a -> m0 Source #

foldr :: (a -> b -> b) -> b -> WSerialT m a -> b Source #

foldr' :: (a -> b -> b) -> b -> WSerialT m a -> b Source #

foldl :: (b -> a -> b) -> b -> WSerialT m a -> b Source #

foldl' :: (b -> a -> b) -> b -> WSerialT m a -> b Source #

foldr1 :: (a -> a -> a) -> WSerialT m a -> a Source #

foldl1 :: (a -> a -> a) -> WSerialT m a -> a Source #

toList :: WSerialT m a -> [a] Source #

null :: WSerialT m a -> Bool Source #

length :: WSerialT m a -> Int Source #

elem :: Eq a => a -> WSerialT m a -> Bool Source #

maximum :: Ord a => WSerialT m a -> a Source #

minimum :: Ord a => WSerialT m a -> a Source #

sum :: Num a => WSerialT m a -> a Source #

product :: Num a => WSerialT m a -> a Source #

Traversable (WSerialT Identity) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

traverse :: Applicative f => (a -> f b) -> WSerialT Identity a -> f (WSerialT Identity b) Source #

sequenceA :: Applicative f => WSerialT Identity (f a) -> f (WSerialT Identity a) Source #

mapM :: Monad m => (a -> m b) -> WSerialT Identity a -> m (WSerialT Identity b) Source #

sequence :: Monad m => WSerialT Identity (m a) -> m (WSerialT Identity a) Source #

Monad m => Applicative (WSerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

pure :: a -> WSerialT m a Source #

(<*>) :: WSerialT m (a -> b) -> WSerialT m a -> WSerialT m b Source #

liftA2 :: (a -> b -> c) -> WSerialT m a -> WSerialT m b -> WSerialT m c Source #

(*>) :: WSerialT m a -> WSerialT m b -> WSerialT m b Source #

(<*) :: WSerialT m a -> WSerialT m b -> WSerialT m a Source #

Monad m => Functor (WSerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

fmap :: (a -> b) -> WSerialT m a -> WSerialT m b Source #

(<$) :: a -> WSerialT m b -> WSerialT m a Source #

Monad m => Monad (WSerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

(>>=) :: WSerialT m a -> (a -> WSerialT m b) -> WSerialT m b Source #

(>>) :: WSerialT m a -> WSerialT m b -> WSerialT m b Source #

return :: a -> WSerialT m a Source #

NFData1 (WSerialT Identity) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

liftRnf :: (a -> ()) -> WSerialT Identity a -> () Source #

MonadThrow m => MonadThrow (WSerialT m) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

throwM :: Exception e => e -> WSerialT m a Source #

a ~ Char => IsString (WSerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Monoid (WSerialT m a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

mempty :: WSerialT m a Source #

mappend :: WSerialT m a -> WSerialT m a -> WSerialT m a Source #

mconcat :: [WSerialT m a] -> WSerialT m a Source #

Semigroup (WSerialT m a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

(<>) :: WSerialT m a -> WSerialT m a -> WSerialT m a Source #

sconcat :: NonEmpty (WSerialT m a) -> WSerialT m a Source #

stimes :: Integral b => b -> WSerialT m a -> WSerialT m a Source #

IsList (WSerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Associated Types

type Item (WSerialT Identity a) Source #

Read a => Read (WSerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Show a => Show (WSerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

NFData a => NFData (WSerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Methods

rnf :: WSerialT Identity a -> () Source #

Eq a => Eq (WSerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

Ord a => Ord (WSerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

type Item (WSerialT Identity a) Source # 
Instance details

Defined in Streamly.Internal.Data.Stream.Serial

type Item (WSerialT Identity a) = a

type WSerial = WSerialT IO Source #

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

Since: 0.2.0 (Streamly)

Since: 0.8.0

wSerial :: WSerialT m a -> WSerialT m a -> WSerialT m a infixr 6 Source #

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

consMWSerial :: Monad m => m a -> WSerialT m a -> WSerialT m a Source #

Construction

cons :: a -> SerialT m a -> SerialT m a infixr 5 Source #

consM :: Monad m => m a -> SerialT m a -> SerialT m a infixr 5 Source #

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

Generate an infinite stream by repeating a pure value.

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

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

fromList :: IsList l => [Item l] -> l Source #

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

Elimination

toList :: IsList l => l -> [Item l] Source #

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

Transformation

map :: Monad m => (a -> b) -> SerialT m a -> SerialT m b Source #

map = fmap

Same as fmap.

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

Since: 0.4.0

mapM :: Monad m => (a -> m b) -> SerialT m a -> SerialT m b Source #