{-# LANGUAGE UndecidableInstances #-}
module Streamly.Internal.Data.Stream.Serial
(
SerialT(..)
, Serial
, serial
, WSerialT(..)
, WSerial
, wSerialK
, wSerial
, wSerialFst
, wSerialMin
, consMWSerial
, cons
, consM
, repeat
, unfoldrM
, fromList
, toList
, map
, mapM
, StreamT
, InterleavedT
)
where
import Control.Applicative (liftA2)
import Control.DeepSeq (NFData(..))
#if MIN_VERSION_deepseq(1,4,3)
import Control.DeepSeq (NFData1(..))
#endif
import Control.Monad.Base (MonadBase(..), liftBaseDefault)
import Control.Monad.Catch (MonadThrow, throwM)
import Control.Monad.IO.Class (MonadIO(..))
import Control.Monad.Reader.Class (MonadReader(..))
import Control.Monad.State.Class (MonadState(..))
import Control.Monad.Trans.Class (MonadTrans(lift))
import Data.Foldable (Foldable(foldl'), fold)
import Data.Functor.Identity (Identity(..), runIdentity)
import Data.Maybe (fromMaybe)
import Data.Semigroup (Endo(..))
#if __GLASGOW_HASKELL__ < 808
import Data.Semigroup (Semigroup(..))
#endif
import GHC.Exts (IsList(..), IsString(..))
import Text.Read
( Lexeme(Ident), lexP, parens, prec, readPrec, readListPrec
, readListPrecDefault)
import Streamly.Internal.BaseCompat ((#.), errorWithoutStackTrace, oneShot)
import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
import Streamly.Internal.Data.Stream.StreamK.Type
(Stream, mkStream, foldStream)
import qualified Streamly.Internal.Data.Stream.Prelude as P
import qualified Streamly.Internal.Data.Stream.StreamD.Generate as D
import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
import Prelude hiding (map, mapM, errorWithoutStackTrace, repeat)
#include "Instances.hs"
#include "inline.hs"
newtype SerialT m a = SerialT {forall (m :: * -> *) a. SerialT m a -> Stream m a
getSerialT :: Stream m a}
deriving (NonEmpty (SerialT m a) -> SerialT m a
SerialT m a -> SerialT m a -> SerialT m a
forall b. Integral b => b -> SerialT m a -> SerialT m a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall (m :: * -> *) a. NonEmpty (SerialT m a) -> SerialT m a
forall (m :: * -> *) a. SerialT m a -> SerialT m a -> SerialT m a
forall (m :: * -> *) a b.
Integral b =>
b -> SerialT m a -> SerialT m a
stimes :: forall b. Integral b => b -> SerialT m a -> SerialT m a
$cstimes :: forall (m :: * -> *) a b.
Integral b =>
b -> SerialT m a -> SerialT m a
sconcat :: NonEmpty (SerialT m a) -> SerialT m a
$csconcat :: forall (m :: * -> *) a. NonEmpty (SerialT m a) -> SerialT m a
<> :: SerialT m a -> SerialT m a -> SerialT m a
$c<> :: forall (m :: * -> *) a. SerialT m a -> SerialT m a -> SerialT m a
Semigroup, SerialT m a
[SerialT m a] -> SerialT m a
SerialT m a -> SerialT m a -> SerialT m a
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall (m :: * -> *) a. Semigroup (SerialT m a)
forall (m :: * -> *) a. SerialT m a
forall (m :: * -> *) a. [SerialT m a] -> SerialT m a
forall (m :: * -> *) a. SerialT m a -> SerialT m a -> SerialT m a
mconcat :: [SerialT m a] -> SerialT m a
$cmconcat :: forall (m :: * -> *) a. [SerialT m a] -> SerialT m a
mappend :: SerialT m a -> SerialT m a -> SerialT m a
$cmappend :: forall (m :: * -> *) a. SerialT m a -> SerialT m a -> SerialT m a
mempty :: SerialT m a
$cmempty :: forall (m :: * -> *) a. SerialT m a
Monoid, forall (m :: * -> *) a. Monad m => m a -> SerialT m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: forall (m :: * -> *) a. Monad m => m a -> SerialT m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> SerialT m a
MonadTrans)
type Serial = SerialT IO
{-# DEPRECATED StreamT "Please use 'SerialT' instead." #-}
type StreamT = SerialT
{-# INLINE cons #-}
cons :: a -> SerialT m a -> SerialT m a
cons :: forall a (m :: * -> *). a -> SerialT m a -> SerialT m a
cons a
x (SerialT Stream m a
ms) = forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). a -> Stream m a -> Stream m a
K.cons a
x Stream m a
ms
{-# INLINE consM #-}
{-# SPECIALIZE consM :: IO a -> SerialT IO a -> SerialT IO a #-}
consM :: Monad m => m a -> SerialT m a -> SerialT m a
consM :: forall (m :: * -> *) a.
Monad m =>
m a -> SerialT m a -> SerialT m a
consM m a
m (SerialT Stream m a
ms) = forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => m a -> Stream m a -> Stream m a
K.consM m a
m Stream m a
ms
{-# INLINE_NORMAL repeat #-}
repeat :: Monad m => a -> SerialT m a
repeat :: forall (m :: * -> *) a. Monad m => a -> SerialT m a
repeat = forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => Stream m a -> Stream m a
D.toStreamK forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> Stream m a
D.repeat
{-# INLINE serial #-}
serial :: SerialT m a -> SerialT m a -> SerialT m a
serial :: forall (m :: * -> *) a. SerialT m a -> SerialT m a -> SerialT m a
serial = forall a. Semigroup a => a -> a -> a
(<>)
instance Monad m => Monad (SerialT m) where
return :: forall a. a -> SerialT m a
return = forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE (>>=) #-}
>>= :: forall a b. SerialT m a -> (a -> SerialT m b) -> SerialT m b
(>>=) (SerialT Stream m a
m) a -> SerialT m b
f = forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a.
(Stream m b -> Stream m b -> Stream m b)
-> Stream m a -> (a -> Stream m b) -> Stream m b
K.bindWith forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
K.serial Stream m a
m (forall (m :: * -> *) a. SerialT m a -> Stream m a
getSerialT forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> SerialT m b
f)
{-# INLINE (>>) #-}
>> :: forall a b. SerialT m a -> SerialT m b -> SerialT m b
(>>) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
{-# INLINE mapM #-}
mapM :: Monad m => (a -> m b) -> SerialT m a -> SerialT m b
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SerialT m a -> SerialT m b
mapM a -> m b
f (SerialT Stream m a
m) = forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => Stream m a -> Stream m a
D.toStreamK forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Stream m a -> Stream m b
D.mapM a -> m b
f forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Applicative m => Stream m a -> Stream m a
D.fromStreamK Stream m a
m
{-# INLINE map #-}
map :: Monad m => (a -> b) -> SerialT m a -> SerialT m b
map :: forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> SerialT m a -> SerialT m b
map a -> b
f = forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SerialT m a -> SerialT m b
mapM (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
{-# INLINE apSerial #-}
apSerial :: Monad m => SerialT m (a -> b) -> SerialT m a -> SerialT m b
apSerial :: forall (m :: * -> *) a b.
Monad m =>
SerialT m (a -> b) -> SerialT m a -> SerialT m b
apSerial (SerialT Stream m (a -> b)
m1) (SerialT Stream m a
m2) =
forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => Stream m a -> Stream m a
D.toStreamK forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Applicative m => Stream m a -> Stream m a
D.fromStreamK Stream m (a -> b)
m1 forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *) a. Applicative m => Stream m a -> Stream m a
D.fromStreamK Stream m a
m2
{-# INLINE apSequence #-}
apSequence :: Monad m => SerialT m a -> SerialT m b -> SerialT m b
apSequence :: forall (m :: * -> *) a b.
Monad m =>
SerialT m a -> SerialT m b -> SerialT m b
apSequence (SerialT Stream m a
m1) (SerialT Stream m b
m2) =
forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => Stream m a -> Stream m a
D.toStreamK forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Applicative m => Stream m a -> Stream m a
D.fromStreamK Stream m a
m1 forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) a. Applicative m => Stream m a -> Stream m a
D.fromStreamK Stream m b
m2
{-# INLINE apDiscardSnd #-}
apDiscardSnd :: Monad m => SerialT m a -> SerialT m b -> SerialT m a
apDiscardSnd :: forall (m :: * -> *) a b.
Monad m =>
SerialT m a -> SerialT m b -> SerialT m a
apDiscardSnd (SerialT Stream m a
m1) (SerialT Stream m b
m2) =
forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => Stream m a -> Stream m a
D.toStreamK forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Applicative m => Stream m a -> Stream m a
D.fromStreamK Stream m a
m1 forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) a. Applicative m => Stream m a -> Stream m a
D.fromStreamK Stream m b
m2
instance Monad m => Applicative (SerialT m) where
{-# INLINE pure #-}
pure :: forall a. a -> SerialT m a
pure = forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a (m :: * -> *). a -> Stream m a
K.fromPure
{-# INLINE (<*>) #-}
<*> :: forall a b. SerialT m (a -> b) -> SerialT m a -> SerialT m b
(<*>) = forall (m :: * -> *) a b.
Monad m =>
SerialT m (a -> b) -> SerialT m a -> SerialT m b
apSerial
#if MIN_VERSION_base(4,10,0)
{-# INLINE liftA2 #-}
liftA2 :: forall a b c.
(a -> b -> c) -> SerialT m a -> SerialT m b -> SerialT m c
liftA2 a -> b -> c
f SerialT m a
x = forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>) (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b -> c
f SerialT m a
x)
#endif
{-# INLINE (*>) #-}
*> :: forall a b. SerialT m a -> SerialT m b -> SerialT m b
(*>) = forall (m :: * -> *) a b.
Monad m =>
SerialT m a -> SerialT m b -> SerialT m b
apSequence
{-# INLINE (<*) #-}
<* :: forall a b. SerialT m a -> SerialT m b -> SerialT m a
(<*) = forall (m :: * -> *) a b.
Monad m =>
SerialT m a -> SerialT m b -> SerialT m a
apDiscardSnd
MONAD_COMMON_INSTANCES(SerialT,)
LIST_INSTANCES(SerialT)
NFDATA1_INSTANCE(SerialT)
FOLDABLE_INSTANCE(SerialT)
TRAVERSABLE_INSTANCE(SerialT)
newtype WSerialT m a = WSerialT {forall (m :: * -> *) a. WSerialT m a -> Stream m a
getWSerialT :: Stream m a}
deriving (forall (m :: * -> *) a. Monad m => m a -> WSerialT m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: forall (m :: * -> *) a. Monad m => m a -> WSerialT m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> WSerialT m a
MonadTrans)
type WSerial = WSerialT IO
{-# DEPRECATED InterleavedT "Please use 'WSerialT' instead." #-}
type InterleavedT = WSerialT
{-# INLINE consMWSerial #-}
{-# SPECIALIZE consMWSerial :: IO a -> WSerialT IO a -> WSerialT IO a #-}
consMWSerial :: Monad m => m a -> WSerialT m a -> WSerialT m a
consMWSerial :: forall (m :: * -> *) a.
Monad m =>
m a -> WSerialT m a -> WSerialT m a
consMWSerial m a
m (WSerialT Stream m a
ms) = forall (m :: * -> *) a. Stream m a -> WSerialT m a
WSerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => m a -> Stream m a -> Stream m a
K.consM m a
m Stream m a
ms
infixr 6 `wSerial`
{-# INLINE wSerialK #-}
wSerialK :: Stream m a -> Stream m a -> Stream m a
wSerialK :: forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialK Stream m a
m1 Stream m a
m2 = forall (m :: * -> *) a.
(forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
mkStream forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> Stream m a -> m r
yld a -> m r
sng m r
stp -> do
let stop :: m r
stop = forall (m :: * -> *) a r.
State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> Stream m a
-> m r
foldStream State Stream m a
st a -> Stream m a -> m r
yld a -> m r
sng m r
stp Stream m a
m2
single :: a -> m r
single a
a = a -> Stream m a -> m r
yld a
a Stream m a
m2
yieldk :: a -> Stream m a -> m r
yieldk a
a Stream m a
r = a -> Stream m a -> m r
yld a
a (forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialK Stream m a
m2 Stream m a
r)
forall (m :: * -> *) a r.
State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> Stream m a
-> m r
foldStream State Stream m a
st a -> Stream m a -> m r
yieldk a -> m r
single m r
stop Stream m a
m1
{-# INLINE wSerial #-}
wSerial :: WSerialT m a -> WSerialT m a -> WSerialT m a
wSerial :: forall (m :: * -> *) a.
WSerialT m a -> WSerialT m a -> WSerialT m a
wSerial (WSerialT Stream m a
m1) (WSerialT Stream m a
m2) = forall (m :: * -> *) a. Stream m a -> WSerialT m a
WSerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialK Stream m a
m1 Stream m a
m2
{-# INLINE wSerialFstK #-}
wSerialFstK :: Stream m a -> Stream m a -> Stream m a
wSerialFstK :: forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialFstK Stream m a
m1 Stream m a
m2 = forall (m :: * -> *) a.
(forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
mkStream forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> Stream m a -> m r
yld a -> m r
sng m r
stp -> do
let yieldFirst :: a -> Stream m a -> m r
yieldFirst a
a Stream m a
r = a -> Stream m a -> m r
yld a
a (forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
yieldSecond Stream m a
r Stream m a
m2)
in forall (m :: * -> *) a r.
State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> Stream m a
-> m r
foldStream State Stream m a
st a -> Stream m a -> m r
yieldFirst a -> m r
sng m r
stp Stream m a
m1
where
yieldSecond :: Stream m a -> Stream m a -> Stream m a
yieldSecond Stream m a
s1 Stream m a
s2 = forall (m :: * -> *) a.
(forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
mkStream forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> Stream m a -> m r
yld a -> m r
sng m r
stp -> do
let stop :: m r
stop = forall (m :: * -> *) a r.
State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> Stream m a
-> m r
foldStream State Stream m a
st a -> Stream m a -> m r
yld a -> m r
sng m r
stp Stream m a
s1
single :: a -> m r
single a
a = a -> Stream m a -> m r
yld a
a Stream m a
s1
yieldk :: a -> Stream m a -> m r
yieldk a
a Stream m a
r = a -> Stream m a -> m r
yld a
a (forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialK Stream m a
s1 Stream m a
r)
in forall (m :: * -> *) a r.
State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> Stream m a
-> m r
foldStream State Stream m a
st a -> Stream m a -> m r
yieldk a -> m r
single m r
stop Stream m a
s2
{-# INLINE wSerialFst #-}
wSerialFst :: WSerialT m a -> WSerialT m a -> WSerialT m a
wSerialFst :: forall (m :: * -> *) a.
WSerialT m a -> WSerialT m a -> WSerialT m a
wSerialFst (WSerialT Stream m a
m1) (WSerialT Stream m a
m2) = forall (m :: * -> *) a. Stream m a -> WSerialT m a
WSerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialFstK Stream m a
m1 Stream m a
m2
{-# INLINE wSerialMinK #-}
wSerialMinK :: Stream m a -> Stream m a -> Stream m a
wSerialMinK :: forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialMinK Stream m a
m1 Stream m a
m2 = forall (m :: * -> *) a.
(forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
mkStream forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> Stream m a -> m r
yld a -> m r
_ m r
stp -> do
let stop :: m r
stop = m r
stp
single :: a -> m r
single a
a = a -> Stream m a -> m r
yld a
a (forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialMinK Stream m a
m2 forall (m :: * -> *) a. Stream m a
K.nil)
yieldk :: a -> Stream m a -> m r
yieldk a
a Stream m a
r = a -> Stream m a -> m r
yld a
a (forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialMinK Stream m a
m2 Stream m a
r)
forall (m :: * -> *) a r.
State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> Stream m a
-> m r
foldStream State Stream m a
st a -> Stream m a -> m r
yieldk a -> m r
single m r
stop Stream m a
m1
{-# INLINE wSerialMin #-}
wSerialMin :: WSerialT m a -> WSerialT m a -> WSerialT m a
wSerialMin :: forall (m :: * -> *) a.
WSerialT m a -> WSerialT m a -> WSerialT m a
wSerialMin (WSerialT Stream m a
m1) (WSerialT Stream m a
m2) = forall (m :: * -> *) a. Stream m a -> WSerialT m a
WSerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialMinK Stream m a
m1 Stream m a
m2
instance Semigroup (WSerialT m a) where
<> :: WSerialT m a -> WSerialT m a -> WSerialT m a
(<>) = forall (m :: * -> *) a.
WSerialT m a -> WSerialT m a -> WSerialT m a
wSerial
instance Monoid (WSerialT m a) where
mempty :: WSerialT m a
mempty = forall (m :: * -> *) a. Stream m a -> WSerialT m a
WSerialT forall (m :: * -> *) a. Stream m a
K.nil
mappend :: WSerialT m a -> WSerialT m a -> WSerialT m a
mappend = forall a. Semigroup a => a -> a -> a
(<>)
{-# INLINE apWSerial #-}
apWSerial :: Monad m => WSerialT m (a -> b) -> WSerialT m a -> WSerialT m b
apWSerial :: forall (m :: * -> *) a b.
Monad m =>
WSerialT m (a -> b) -> WSerialT m a -> WSerialT m b
apWSerial (WSerialT Stream m (a -> b)
m1) (WSerialT Stream m a
m2) =
let f :: (a -> b) -> Stream m b
f a -> b
x1 = forall (m :: * -> *) b a.
(Stream m b -> Stream m b -> Stream m b)
-> (a -> Stream m b) -> Stream m a -> Stream m b
K.concatMapWith forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialK (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
x1) Stream m a
m2
in forall (m :: * -> *) a. Stream m a -> WSerialT m a
WSerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a.
(Stream m b -> Stream m b -> Stream m b)
-> (a -> Stream m b) -> Stream m a -> Stream m b
K.concatMapWith forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialK forall {b}. (a -> b) -> Stream m b
f Stream m (a -> b)
m1
instance Monad m => Applicative (WSerialT m) where
{-# INLINE pure #-}
pure :: forall a. a -> WSerialT m a
pure = forall (m :: * -> *) a. Stream m a -> WSerialT m a
WSerialT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a (m :: * -> *). a -> Stream m a
K.fromPure
{-# INLINE (<*>) #-}
<*> :: forall a b. WSerialT m (a -> b) -> WSerialT m a -> WSerialT m b
(<*>) = forall (m :: * -> *) a b.
Monad m =>
WSerialT m (a -> b) -> WSerialT m a -> WSerialT m b
apWSerial
instance Monad m => Monad (WSerialT m) where
return :: forall a. a -> WSerialT m a
return = forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE (>>=) #-}
>>= :: forall a b. WSerialT m a -> (a -> WSerialT m b) -> WSerialT m b
(>>=) (WSerialT Stream m a
m) a -> WSerialT m b
f = forall (m :: * -> *) a. Stream m a -> WSerialT m a
WSerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a.
(Stream m b -> Stream m b -> Stream m b)
-> Stream m a -> (a -> Stream m b) -> Stream m b
K.bindWith forall (m :: * -> *) a. Stream m a -> Stream m a -> Stream m a
wSerialK Stream m a
m (forall (m :: * -> *) a. WSerialT m a -> Stream m a
getWSerialT forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> WSerialT m b
f)
MONAD_COMMON_INSTANCES(WSerialT,)
LIST_INSTANCES(WSerialT)
NFDATA1_INSTANCE(WSerialT)
FOLDABLE_INSTANCE(WSerialT)
TRAVERSABLE_INSTANCE(WSerialT)
{-# INLINE unfoldrM #-}
unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> SerialT m a
unfoldrM :: forall (m :: * -> *) b a.
Monad m =>
(b -> m (Maybe (a, b))) -> b -> SerialT m a
unfoldrM b -> m (Maybe (a, b))
step b
seed = forall (m :: * -> *) a. Stream m a -> SerialT m a
SerialT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => Stream m a -> Stream m a
D.toStreamK (forall (m :: * -> *) s a.
Monad m =>
(s -> m (Maybe (a, s))) -> s -> Stream m a
D.unfoldrM b -> m (Maybe (a, b))
step b
seed)