{-# LANGUAGE UndecidableInstances #-}
#include "inline.hs"
module Streamly.Internal.Data.Stream.StreamK.Type
(
IsStream (..)
, adapt
, Stream (..)
, mkStream
, fromStopK
, fromYieldK
, consK
, foldStream
, foldStreamShared
, foldl'
, foldlx'
, foldrM
, foldrS
, foldrSShared
, foldrSM
, build
, buildS
, buildM
, buildSM
, sharedM
, augmentS
, augmentSM
, cons
, (.:)
, consMStream
, consMBy
, fromEffect
, fromPure
, nil
, nilM
, conjoin
, serial
, map
, mapM
, mapMSerial
, unShare
, concatMapBy
, concatMap
, bindWith
, concatPairsWith
, apWith
, apSerial
, apSerialDiscardFst
, apSerialDiscardSnd
, Streaming
)
where
import Control.Monad (ap, (>=>))
import Control.Monad.Trans.Class (MonadTrans(lift))
import Data.Kind (Type)
#if __GLASGOW_HASKELL__ < 808
import Data.Semigroup (Semigroup(..))
#endif
import Prelude hiding (map, mapM, concatMap, foldr)
import Streamly.Internal.Data.SVar
newtype Stream m a =
MkStream (forall r.
State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> m r
)
infixr 5 `consM`
infixr 5 |:
class
#if __GLASGOW_HASKELL__ >= 806
( forall m a. MonadAsync m => Semigroup (t m a)
, forall m a. MonadAsync m => Monoid (t m a)
, forall m. Monad m => Functor (t m)
, forall m. MonadAsync m => Applicative (t m)
) =>
#endif
IsStream t where
toStream :: t m a -> Stream m a
fromStream :: Stream m a -> t m a
consM :: MonadAsync m => m a -> t m a -> t m a
(|:) :: MonadAsync m => m a -> t m a -> t m a
{-# DEPRECATED Streaming "Please use IsStream instead." #-}
type Streaming = IsStream
adapt :: (IsStream t1, IsStream t2) => t1 m a -> t2 m a
adapt :: t1 m a -> t2 m a
adapt = Stream m a -> t2 m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
Stream m a -> t m a
fromStream (Stream m a -> t2 m a)
-> (t1 m a -> Stream m a) -> t1 m a -> t2 m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t1 m a -> Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> Stream m a
toStream
{-# INLINE_EARLY mkStream #-}
mkStream :: IsStream t
=> (forall r. State Stream m a
-> (a -> t m a -> m r)
-> (a -> m r)
-> m r
-> m r)
-> t m a
mkStream :: (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream forall r.
State Stream m a -> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r
k = Stream m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
Stream m a -> t m a
fromStream (Stream m a -> t m a) -> Stream m a -> t m a
forall a b. (a -> b) -> a -> b
$ (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
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 r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a)
-> (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
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 ->
let yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = a -> Stream m a -> m r
yld a
a (t m a -> Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> Stream m a
toStream t m a
r)
in State Stream m a -> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r
forall r.
State Stream m a -> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r
k State Stream m a
st a -> t m a -> m r
forall (t :: (* -> *) -> * -> *). IsStream t => a -> t m a -> m r
yieldk a -> m r
sng m r
stp
{-# RULES "mkStream from stream" mkStream = mkStreamFromStream #-}
mkStreamFromStream :: IsStream t
=> (forall r. State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> m r)
-> t m a
mkStreamFromStream :: (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStreamFromStream forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
k = Stream m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
Stream m a -> t m a
fromStream (Stream m a -> t m a) -> Stream m a -> t m a
forall a b. (a -> b) -> a -> b
$ (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
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 r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
k
{-# RULES "mkStream stream" mkStream = mkStreamStream #-}
mkStreamStream
:: (forall r. State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> m r)
-> Stream m a
mkStreamStream :: (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
mkStreamStream = (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
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
type StopK m = forall r. m r -> m r
type YieldK m a = forall r. (a -> m r) -> m r
_wrapM :: Monad m => m a -> YieldK m a
_wrapM :: m a -> YieldK m a
_wrapM m a
m = \a -> m r
k -> m a
m m a -> (a -> m r) -> m r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> m r
k
fromStopK :: IsStream t => StopK m -> t m a
fromStopK :: StopK m -> t m a
fromStopK StopK m
k = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
_ a -> t m a -> m r
_ a -> m r
_ m r
stp -> m r -> m r
StopK m
k m r
stp
fromYieldK :: IsStream t => YieldK m a -> t m a
fromYieldK :: YieldK m a -> t m a
fromYieldK YieldK m a
k = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
_ a -> t m a -> m r
_ a -> m r
sng m r
_ -> (a -> m r) -> m r
YieldK m a
k a -> m r
sng
consK :: IsStream t => YieldK m a -> t m a -> t m a
consK :: YieldK m a -> t m a -> t m a
consK YieldK m a
k t m a
r = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
_ a -> t m a -> m r
yld a -> m r
_ m r
_ -> (a -> m r) -> m r
YieldK m a
k (\a
x -> a -> t m a -> m r
yld a
x t m a
r)
infixr 5 `cons`
{-# INLINE_NORMAL cons #-}
cons :: IsStream t => a -> t m a -> t m a
cons :: a -> t m a -> t m a
cons a
a t m a
r = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
_ a -> t m a -> m r
yld a -> m r
_ m r
_ -> a -> t m a -> m r
yld a
a t m a
r
infixr 5 .:
{-# INLINE (.:) #-}
(.:) :: IsStream t => a -> t m a -> t m a
.: :: a -> t m a -> t m a
(.:) = a -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
a -> t m a -> t m a
cons
{-# INLINE_NORMAL nil #-}
nil :: IsStream t => t m a
nil :: t m a
nil = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
_ a -> t m a -> m r
_ a -> m r
_ m r
stp -> m r
stp
{-# INLINE_NORMAL nilM #-}
nilM :: (IsStream t, Monad m) => m b -> t m a
nilM :: m b -> t m a
nilM m b
m = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
_ a -> t m a -> m r
_ a -> m r
_ m r
stp -> m b
m m b -> m r -> m r
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> m r
stp
{-# INLINE_NORMAL fromPure #-}
fromPure :: IsStream t => a -> t m a
fromPure :: a -> t m a
fromPure a
a = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
_ a -> t m a -> m r
_ a -> m r
single m r
_ -> a -> m r
single a
a
{-# INLINE_NORMAL fromEffect #-}
fromEffect :: (Monad m, IsStream t) => m a -> t m a
fromEffect :: m a -> t m a
fromEffect m a
m = Stream m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
Stream m a -> t m a
fromStream (Stream m a -> t m a) -> Stream m a -> t m a
forall a b. (a -> b) -> a -> b
$ (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a)
-> (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
_ a -> Stream m a -> m r
_ a -> m r
single m r
_ -> m a
m m a -> (a -> m r) -> m r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> m r
single
{-# INLINE consMBy #-}
consMBy :: (IsStream t, MonadAsync m) => (t m a -> t m a -> t m a)
-> m a -> t m a -> t m a
consMBy :: (t m a -> t m a -> t m a) -> m a -> t m a -> t m a
consMBy t m a -> t m a -> t m a
f m a
m t m a
r = (Stream m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
Stream m a -> t m a
fromStream (Stream m a -> t m a) -> Stream m a -> t m a
forall a b. (a -> b) -> a -> b
$ m a -> Stream m a
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a.
(Monad m, IsStream t) =>
m a -> t m a
fromEffect m a
m) t m a -> t m a -> t m a
`f` t m a
r
{-# INLINE_EARLY foldStreamShared #-}
foldStreamShared
:: IsStream t
=> State Stream m a
-> (a -> t m a -> m r)
-> (a -> m r)
-> m r
-> t m a
-> m r
foldStreamShared :: State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp t m a
m =
let yieldk :: a -> Stream m a -> m r
yieldk a
a Stream m a
x = a -> t m a -> m r
yld a
a (Stream m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
Stream m a -> t m a
fromStream Stream m a
x)
MkStream forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
k = t m a -> Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> Stream m a
toStream t m a
m
in State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
k State Stream m a
st a -> Stream m a -> m r
yieldk a -> m r
sng m r
stp
{-# RULES "foldStreamShared from stream"
foldStreamShared = foldStreamSharedStream #-}
foldStreamSharedStream
:: State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> Stream m a
-> m r
foldStreamSharedStream :: State Stream m a
-> (a -> Stream m a -> m r)
-> (a -> m r)
-> m r
-> Stream m a
-> m r
foldStreamSharedStream State Stream m a
st a -> Stream m a -> m r
yld a -> m r
sng m r
stp Stream m a
m =
let MkStream forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
k = Stream m a -> Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> Stream m a
toStream Stream m a
m
in State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
k State Stream m a
st a -> Stream m a -> m r
yld a -> m r
sng m r
stp
{-# INLINE foldStream #-}
foldStream
:: IsStream t
=> State Stream m a
-> (a -> t m a -> m r)
-> (a -> m r)
-> m r
-> t m a
-> m r
foldStream :: State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp t m a
m =
let yieldk :: a -> Stream m a -> m r
yieldk a
a Stream m a
x = a -> t m a -> m r
yld a
a (Stream m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
Stream m a -> t m a
fromStream Stream m a
x)
MkStream forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
k = t m a -> Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> Stream m a
toStream t m a
m
in State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r
k (State Stream m a -> State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m a
st) a -> Stream m a -> m r
yieldk a -> m r
sng m r
stp
{-# INLINE consMStream #-}
{-# SPECIALIZE consMStream :: IO a -> Stream IO a -> Stream IO a #-}
consMStream :: (Monad m) => m a -> Stream m a -> Stream m a
consMStream :: m a -> Stream m a -> Stream m a
consMStream m a
m Stream m a
r = (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
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 r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a)
-> (forall r.
State Stream m a
-> (a -> Stream m a -> m r) -> (a -> m r) -> m r -> m r)
-> Stream m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
_ a -> Stream m a -> m r
yld a -> m r
_ m r
_ -> m a
m m a -> (a -> m r) -> m r
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
a -> a -> Stream m a -> m r
yld a
a Stream m a
r
instance IsStream Stream where
toStream :: Stream m a -> Stream m a
toStream = Stream m a -> Stream m a
forall a. a -> a
id
fromStream :: Stream m a -> Stream m a
fromStream = Stream m a -> Stream m a
forall a. a -> a
id
{-# INLINE consM #-}
{-# SPECIALIZE consM :: IO a -> Stream IO a -> Stream IO a #-}
consM :: Monad m => m a -> Stream m a -> Stream m a
consM :: m a -> Stream m a -> Stream m a
consM = m a -> Stream m a -> Stream m a
forall (m :: * -> *) a. Monad m => m a -> Stream m a -> Stream m a
consMStream
{-# INLINE (|:) #-}
{-# SPECIALIZE (|:) :: IO a -> Stream IO a -> Stream IO a #-}
(|:) :: Monad m => m a -> Stream m a -> Stream m a
|: :: m a -> Stream m a -> Stream m a
(|:) = m a -> Stream m a -> Stream m a
forall (m :: * -> *) a. Monad m => m a -> Stream m a -> Stream m a
consMStream
{-# INLINE foldrSWith #-}
foldrSWith :: IsStream t
=> (forall r. State Stream m b
-> (b -> t m b -> m r)
-> (b -> m r)
-> m r
-> t m b
-> m r)
-> (a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSWith :: (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSWith forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
f a -> t m b -> t m b
step t m b
final t m a
m = t m a -> t m b
forall (t :: (* -> *) -> * -> *). IsStream t => t m a -> t m b
go t m a
m
where
go :: t m a -> t m b
go t m a
m1 = (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b)
-> (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall a b. (a -> b) -> a -> b
$ \State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp ->
let run :: t m b -> m r
run t m b
x = State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
f State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp t m b
x
stop :: m r
stop = t m b -> m r
run t m b
final
single :: a -> m r
single a
a = t m b -> m r
run (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ a -> t m b -> t m b
step a
a t m b
final
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = t m b -> m r
run (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ a -> t m b -> t m b
step a
a (t m a -> t m b
go t m a
r)
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m b -> State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m b
st) a -> t m a -> m r
yieldk a -> m r
single m r
stop t m a
m1
{-# INLINE_NORMAL foldrSShared #-}
foldrSShared :: IsStream t => (a -> t m b -> t m b) -> t m b -> t m a -> t m b
= (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (a -> t m b -> t m b) -> t m b -> t m a -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) b a.
IsStream t =>
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSWith forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared
{-# RULES "foldrSShared/nil"
forall k z. foldrSShared k z nil = z #-}
{-# RULES "foldrSShared/single"
forall k z x. foldrSShared k z (fromPure x) = k x z #-}
{-# INLINE_NORMAL foldrS #-}
foldrS :: IsStream t => (a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrS :: (a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrS = (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (a -> t m b -> t m b) -> t m b -> t m a -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) b a.
IsStream t =>
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSWith forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream
{-# RULES "foldrS/id" foldrS cons nil = \x -> x #-}
{-# RULES "foldrS/nil" forall k z. foldrS k z nil = z #-}
{-# RULES "foldrS/single" forall k z x. foldrS k z (fromPure x) = k x z #-}
{-# INLINE foldrSMWith #-}
foldrSMWith :: (IsStream t, Monad m)
=> (forall r. State Stream m b
-> (b -> t m b -> m r)
-> (b -> m r)
-> m r
-> t m b
-> m r)
-> (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSMWith :: (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSMWith forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
f m a -> t m b -> t m b
step t m b
final t m a
m = t m a -> t m b
forall (t :: (* -> *) -> * -> *). IsStream t => t m a -> t m b
go t m a
m
where
go :: t m a -> t m b
go t m a
m1 = (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b)
-> (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall a b. (a -> b) -> a -> b
$ \State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp ->
let run :: t m b -> m r
run t m b
x = State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
f State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp t m b
x
stop :: m r
stop = t m b -> m r
run t m b
final
single :: a -> m r
single a
a = t m b -> m r
run (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ m a -> t m b -> t m b
step (a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a) t m b
final
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = t m b -> m r
run (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ m a -> t m b -> t m b
step (a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a) (t m a -> t m b
go t m a
r)
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m b -> State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m b
st) a -> t m a -> m r
yieldk a -> m r
single m r
stop t m a
m1
{-# INLINE_NORMAL foldrSM #-}
foldrSM :: (IsStream t, Monad m)
=> (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSM :: (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSM = (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) b a.
(IsStream t, Monad m) =>
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSMWith forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream
{-# RULES "foldrSM/nil" forall k z. foldrSM k z nil = z #-}
{-# RULES "foldrSM/single" forall k z x. foldrSM k z (fromEffect x) = k x z #-}
{-# INLINE_NORMAL foldrSMShared #-}
foldrSMShared :: (IsStream t, Monad m)
=> (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSMShared :: (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSMShared = (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) b a.
(IsStream t, Monad m) =>
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r)
-> (m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSMWith forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared
{-# RULES "foldrSMShared/nil"
forall k z. foldrSMShared k z nil = z #-}
{-# RULES "foldrSMShared/single"
forall k z x. foldrSMShared k z (fromEffect x) = k x z #-}
{-# INLINE_NORMAL build #-}
build :: IsStream t => forall a. (forall b. (a -> b -> b) -> b -> b) -> t m a
build :: forall a. (forall b. (a -> b -> b) -> b -> b) -> t m a
build forall b. (a -> b -> b) -> b -> b
g = (a -> t m a -> t m a) -> t m a -> t m a
forall b. (a -> b -> b) -> b -> b
g a -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
a -> t m a -> t m a
cons t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a
nil
{-# RULES "foldrM/build"
forall k z (g :: forall b. (a -> b -> b) -> b -> b).
foldrM k z (build g) = g k z #-}
{-# RULES "foldrS/build"
forall k z (g :: forall b. (a -> b -> b) -> b -> b).
foldrS k z (build g) = g k z #-}
{-# RULES "foldrS/cons/build"
forall k z x (g :: forall b. (a -> b -> b) -> b -> b).
foldrS k z (x `cons` build g) = k x (g k z) #-}
{-# RULES "foldrSShared/build"
forall k z (g :: forall b. (a -> b -> b) -> b -> b).
foldrSShared k z (build g) = g k z #-}
{-# RULES "foldrSShared/cons/build"
forall k z x (g :: forall b. (a -> b -> b) -> b -> b).
foldrSShared k z (x `cons` build g) = k x (g k z) #-}
{-# INLINE_NORMAL buildS #-}
buildS :: IsStream t => ((a -> t m a -> t m a) -> t m a -> t m a) -> t m a
buildS :: ((a -> t m a -> t m a) -> t m a -> t m a) -> t m a
buildS (a -> t m a -> t m a) -> t m a -> t m a
g = (a -> t m a -> t m a) -> t m a -> t m a
g a -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
a -> t m a -> t m a
cons t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a
nil
{-# RULES "foldrS/buildS"
forall k z (g :: (a -> t m a -> t m a) -> t m a -> t m a).
foldrS k z (buildS g) = g k z #-}
{-# RULES "foldrS/cons/buildS"
forall k z x (g :: (a -> t m a -> t m a) -> t m a -> t m a).
foldrS k z (x `cons` buildS g) = k x (g k z) #-}
{-# RULES "foldrSShared/buildS"
forall k z (g :: (a -> t m a -> t m a) -> t m a -> t m a).
foldrSShared k z (buildS g) = g k z #-}
{-# RULES "foldrSShared/cons/buildS"
forall k z x (g :: (a -> t m a -> t m a) -> t m a -> t m a).
foldrSShared k z (x `cons` buildS g) = k x (g k z) #-}
{-# INLINE_NORMAL buildSM #-}
buildSM :: (IsStream t, MonadAsync m)
=> ((m a -> t m a -> t m a) -> t m a -> t m a) -> t m a
buildSM :: ((m a -> t m a -> t m a) -> t m a -> t m a) -> t m a
buildSM (m a -> t m a -> t m a) -> t m a -> t m a
g = (m a -> t m a -> t m a) -> t m a -> t m a
g m a -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, MonadAsync m) =>
m a -> t m a -> t m a
consM t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a
nil
{-# RULES "foldrSM/buildSM"
forall k z (g :: (m a -> t m a -> t m a) -> t m a -> t m a).
foldrSM k z (buildSM g) = g k z #-}
{-# RULES "foldrSMShared/buildSM"
forall k z (g :: (m a -> t m a -> t m a) -> t m a -> t m a).
foldrSMShared k z (buildSM g) = g k z #-}
{-# INLINE_NORMAL buildM #-}
buildM :: (IsStream t, MonadAsync m)
=> (forall r. (a -> t m a -> m r)
-> (a -> m r)
-> m r
-> m r
)
-> t m a
buildM :: (forall r. (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
buildM forall r. (a -> t m a -> m r) -> (a -> m r) -> m r -> m r
g = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
(a -> t m a -> m r) -> (a -> m r) -> m r -> m r
forall r. (a -> t m a -> m r) -> (a -> m r) -> m r -> m r
g (\a
a t m a
r -> State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp (a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a m a -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, MonadAsync m) =>
m a -> t m a -> t m a
`consM` t m a
r)) a -> m r
sng m r
stp
{-# INLINE_NORMAL sharedM #-}
sharedM :: (IsStream t, MonadAsync m)
=> (forall r. (a -> t m a -> m r)
-> (a -> m r)
-> m r
-> m r
)
-> t m a
sharedM :: (forall r. (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
sharedM forall r. (a -> t m a -> m r) -> (a -> m r) -> m r -> m r
g = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
(a -> t m a -> m r) -> (a -> m r) -> m r -> m r
forall r. (a -> t m a -> m r) -> (a -> m r) -> m r -> m r
g (\a
a t m a
r -> State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp (a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a m a -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, MonadAsync m) =>
m a -> t m a -> t m a
`consM` t m a
r)) a -> m r
sng m r
stp
{-# INLINE_NORMAL augmentS #-}
augmentS :: IsStream t
=> ((a -> t m a -> t m a) -> t m a -> t m a) -> t m a -> t m a
augmentS :: ((a -> t m a -> t m a) -> t m a -> t m a) -> t m a -> t m a
augmentS (a -> t m a -> t m a) -> t m a -> t m a
g t m a
xs = (a -> t m a -> t m a) -> t m a -> t m a
g a -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
a -> t m a -> t m a
cons t m a
xs
{-# RULES "augmentS/nil"
forall (g :: (a -> t m a -> t m a) -> t m a -> t m a).
augmentS g nil = buildS g
#-}
{-# RULES "foldrS/augmentS"
forall k z xs (g :: (a -> t m a -> t m a) -> t m a -> t m a).
foldrS k z (augmentS g xs) = g k (foldrS k z xs)
#-}
{-# RULES "augmentS/buildS"
forall (g :: (a -> t m a -> t m a) -> t m a -> t m a)
(h :: (a -> t m a -> t m a) -> t m a -> t m a).
augmentS g (buildS h) = buildS (\c n -> g c (h c n))
#-}
{-# INLINE_NORMAL augmentSM #-}
augmentSM :: (IsStream t, MonadAsync m)
=> ((m a -> t m a -> t m a) -> t m a -> t m a) -> t m a -> t m a
augmentSM :: ((m a -> t m a -> t m a) -> t m a -> t m a) -> t m a -> t m a
augmentSM (m a -> t m a -> t m a) -> t m a -> t m a
g t m a
xs = (m a -> t m a -> t m a) -> t m a -> t m a
g m a -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, MonadAsync m) =>
m a -> t m a -> t m a
consM t m a
xs
{-# RULES "augmentSM/nil"
forall (g :: (m a -> t m a -> t m a) -> t m a -> t m a).
augmentSM g nil = buildSM g
#-}
{-# RULES "foldrSM/augmentSM"
forall k z xs (g :: (m a -> t m a -> t m a) -> t m a -> t m a).
foldrSM k z (augmentSM g xs) = g k (foldrSM k z xs)
#-}
{-# RULES "augmentSM/buildSM"
forall (g :: (m a -> t m a -> t m a) -> t m a -> t m a)
(h :: (m a -> t m a -> t m a) -> t m a -> t m a).
augmentSM g (buildSM h) = buildSM (\c n -> g c (h c n))
#-}
{-# INLINE_NORMAL foldrM #-}
foldrM :: IsStream t => (a -> m b -> m b) -> m b -> t m a -> m b
foldrM :: (a -> m b -> m b) -> m b -> t m a -> m b
foldrM a -> m b -> m b
step m b
acc t m a
m = t m a -> m b
forall (t :: (* -> *) -> * -> *). IsStream t => t m a -> m b
go t m a
m
where
go :: t m a -> m b
go t m a
m1 =
let stop :: m b
stop = m b
acc
single :: a -> m b
single a
a = a -> m b -> m b
step a
a m b
acc
yieldk :: a -> t m a -> m b
yieldk a
a t m a
r = a -> m b -> m b
step a
a (t m a -> m b
go t m a
r)
in State Stream m a
-> (a -> t m a -> m b) -> (a -> m b) -> m b -> t m a -> m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState a -> t m a -> m b
yieldk a -> m b
single m b
stop t m a
m1
{-# INLINE_NORMAL foldrMKWith #-}
foldrMKWith
:: (State Stream m a
-> (a -> t m a -> m b)
-> (a -> m b)
-> m b
-> t m a
-> m b)
-> (a -> m b -> m b)
-> m b
-> ((a -> t m a -> m b) -> (a -> m b) -> m b -> m b)
-> m b
foldrMKWith :: (State Stream m a
-> (a -> t m a -> m b) -> (a -> m b) -> m b -> t m a -> m b)
-> (a -> m b -> m b)
-> m b
-> ((a -> t m a -> m b) -> (a -> m b) -> m b -> m b)
-> m b
foldrMKWith State Stream m a
-> (a -> t m a -> m b) -> (a -> m b) -> m b -> t m a -> m b
f a -> m b -> m b
step m b
acc (a -> t m a -> m b) -> (a -> m b) -> m b -> m b
g = ((a -> t m a -> m b) -> (a -> m b) -> m b -> m b) -> m b
go (a -> t m a -> m b) -> (a -> m b) -> m b -> m b
g
where
go :: ((a -> t m a -> m b) -> (a -> m b) -> m b -> m b) -> m b
go (a -> t m a -> m b) -> (a -> m b) -> m b -> m b
k =
let stop :: m b
stop = m b
acc
single :: a -> m b
single a
a = a -> m b -> m b
step a
a m b
acc
yieldk :: a -> t m a -> m b
yieldk a
a t m a
r = a -> m b -> m b
step a
a (((a -> t m a -> m b) -> (a -> m b) -> m b -> m b) -> m b
go (\a -> t m a -> m b
yld a -> m b
sng m b
stp -> State Stream m a
-> (a -> t m a -> m b) -> (a -> m b) -> m b -> t m a -> m b
f State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState a -> t m a -> m b
yld a -> m b
sng m b
stp t m a
r))
in (a -> t m a -> m b) -> (a -> m b) -> m b -> m b
k a -> t m a -> m b
yieldk a -> m b
single m b
stop
{-# RULES "foldrM/buildM"
forall step acc (g :: (forall r.
(a -> t m a -> m r)
-> (a -> m r)
-> m r
-> m r
)).
foldrM step acc (buildM g) = foldrMKWith foldStream step acc g
#-}
{-# RULES "foldrM/sharedM"
forall step acc (g :: (forall r.
(a -> t m a -> m r)
-> (a -> m r)
-> m r
-> m r
)).
foldrM step acc (sharedM g) = foldrMKWith foldStreamShared step acc g
#-}
{-# INLINE foldlx' #-}
foldlx' :: forall t m a b x. (IsStream t, Monad m)
=> (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
foldlx' :: (x -> a -> x) -> x -> (x -> b) -> t m a -> m b
foldlx' x -> a -> x
step x
begin x -> b
done t m a
m = t m x -> m b
get (t m x -> m b) -> t m x -> m b
forall a b. (a -> b) -> a -> b
$ t m a -> x -> t m x
go t m a
m x
begin
where
{-# NOINLINE get #-}
get :: t m x -> m b
get :: t m x -> m b
get t m x
m1 =
let single :: x -> m b
single = b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> (x -> b) -> x -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> b
done
in State Stream m x
-> (x -> t m x -> m b) -> (x -> m b) -> m b -> t m x -> m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m x
forall a. HasCallStack => a
undefined x -> t m x -> m b
forall a. HasCallStack => a
undefined x -> m b
single m b
forall a. HasCallStack => a
undefined t m x
m1
go :: t m a -> x -> t m x
go :: t m a -> x -> t m x
go t m a
m1 !x
acc = (forall r.
State Stream m x
-> (x -> t m x -> m r) -> (x -> m r) -> m r -> m r)
-> t m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m x
-> (x -> t m x -> m r) -> (x -> m r) -> m r -> m r)
-> t m x)
-> (forall r.
State Stream m x
-> (x -> t m x -> m r) -> (x -> m r) -> m r -> m r)
-> t m x
forall a b. (a -> b) -> a -> b
$ \State Stream m x
_ x -> t m x -> m r
yld x -> m r
sng m r
_ ->
let stop :: m r
stop = x -> m r
sng x
acc
single :: a -> m r
single a
a = x -> m r
sng (x -> m r) -> x -> m r
forall a b. (a -> b) -> a -> b
$ x -> a -> x
step x
acc a
a
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = State Stream m x
-> (x -> t m x -> m r) -> (x -> m r) -> m r -> t m x -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m x
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState x -> t m x -> m r
yld x -> m r
sng m r
forall a. HasCallStack => a
undefined (t m x -> m r) -> t m x -> m r
forall a b. (a -> b) -> a -> b
$
t m a -> x -> t m x
go t m a
r (x -> a -> x
step x
acc a
a)
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState a -> t m a -> m r
yieldk a -> m r
single m r
stop t m a
m1
{-# INLINE foldl' #-}
foldl' :: (IsStream t, Monad m) => (b -> a -> b) -> b -> t m a -> m b
foldl' :: (b -> a -> b) -> b -> t m a -> m b
foldl' b -> a -> b
step b
begin = (b -> a -> b) -> b -> (b -> b) -> t m a -> m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b x.
(IsStream t, Monad m) =>
(x -> a -> x) -> x -> (x -> b) -> t m a -> m b
foldlx' b -> a -> b
step b
begin b -> b
forall a. a -> a
id
infixr 6 `serial`
{-# INLINE serial #-}
serial :: IsStream t => t m a -> t m a -> t m a
serial :: t m a -> t m a -> t m a
serial t m a
m1 t m a
m2 = t m a -> t m a
forall (t :: (* -> *) -> * -> *). IsStream t => t m a -> t m a
go t m a
m1
where
go :: t m a -> t m a
go t m a
m = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
let stop :: m r
stop = State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp t m a
m2
single :: a -> m r
single a
a = a -> t m a -> m r
yld a
a t m a
m2
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = a -> t m a -> m r
yld a
a (t m a -> t m a
go t m a
r)
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m a
st a -> t m a -> m r
yieldk a -> m r
single m r
stop t m a
m
{-# INLINE conjoin #-}
conjoin :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
conjoin :: t m a -> t m a -> t m a
conjoin t m a
xs t m a
ys = ((m a -> t m a -> t m a) -> t m a -> t m a) -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, MonadAsync m) =>
((m a -> t m a -> t m a) -> t m a -> t m a) -> t m a -> t m a
augmentSM (\m a -> t m a -> t m a
c t m a
n -> (m a -> t m a -> t m a) -> t m a -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSM m a -> t m a -> t m a
c t m a
n t m a
xs) t m a
ys
instance Semigroup (Stream m a) where
<> :: Stream m a -> Stream m a -> Stream m a
(<>) = Stream m a -> Stream m a -> Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a -> t m a
serial
instance Monoid (Stream m a) where
mempty :: Stream m a
mempty = Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a
nil
mappend :: Stream m a -> Stream m a -> Stream m a
mappend = Stream m a -> Stream m a -> Stream m a
forall a. Semigroup a => a -> a -> a
(<>)
{-# INLINE_LATE mapFB #-}
mapFB :: forall (t :: (Type -> Type) -> Type -> Type) b m a.
(b -> t m b -> t m b) -> (a -> b) -> a -> t m b -> t m b
mapFB :: (b -> t m b -> t m b) -> (a -> b) -> a -> t m b -> t m b
mapFB b -> t m b -> t m b
c a -> b
f = \a
x t m b
ys -> b -> t m b -> t m b
c (a -> b
f a
x) t m b
ys
#undef Type
{-# RULES
"mapFB/mapFB" forall c f g. mapFB (mapFB c f) g = mapFB c (f . g)
"mapFB/id" forall c. mapFB c (\x -> x) = c
#-}
{-# INLINE map #-}
map :: IsStream t => (a -> b) -> t m a -> t m b
map :: (a -> b) -> t m a -> t m b
map a -> b
f t m a
xs = ((b -> t m b -> t m b) -> t m b -> t m b) -> t m b
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
((a -> t m a -> t m a) -> t m a -> t m a) -> t m a
buildS (\b -> t m b -> t m b
c t m b
n -> (a -> t m b -> t m b) -> t m b -> t m a -> t m b
forall (t :: (* -> *) -> * -> *) a (m :: * -> *) b.
IsStream t =>
(a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrS ((b -> t m b -> t m b) -> (a -> b) -> a -> t m b -> t m b
forall (t :: (* -> *) -> * -> *) b (m :: * -> *) a.
(b -> t m b -> t m b) -> (a -> b) -> a -> t m b -> t m b
mapFB b -> t m b -> t m b
c a -> b
f) t m b
n t m a
xs)
{-# INLINE_LATE mapMFB #-}
mapMFB :: Monad m => (m b -> t m b -> t m b) -> (a -> m b) -> m a -> t m b -> t m b
mapMFB :: (m b -> t m b -> t m b) -> (a -> m b) -> m a -> t m b -> t m b
mapMFB m b -> t m b -> t m b
c a -> m b
f = \m a
x t m b
ys -> m b -> t m b -> t m b
c (m a
x m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> m b
f) t m b
ys
{-# RULES
"mapMFB/mapMFB" forall c f g. mapMFB (mapMFB c f) g = mapMFB c (f >=> g)
#-}
{-# INLINE mapM #-}
mapM :: (IsStream t, MonadAsync m) => (a -> m b) -> t m a -> t m b
mapM :: (a -> m b) -> t m a -> t m b
mapM a -> m b
f = (a -> t m b -> t m b) -> t m b -> t m a -> t m b
forall (t :: (* -> *) -> * -> *) a (m :: * -> *) b.
IsStream t =>
(a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSShared (\a
x t m b
xs -> a -> m b
f a
x m b -> t m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, MonadAsync m) =>
m a -> t m a -> t m a
`consM` t m b
xs) t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a
nil
{-# INLINE mapMSerial #-}
mapMSerial :: MonadAsync m => (a -> m b) -> Stream m a -> Stream m b
mapMSerial :: (a -> m b) -> Stream m a -> Stream m b
mapMSerial a -> m b
f Stream m a
xs = ((m b -> Stream m b -> Stream m b) -> Stream m b -> Stream m b)
-> Stream m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, MonadAsync m) =>
((m a -> t m a -> t m a) -> t m a -> t m a) -> t m a
buildSM (\m b -> Stream m b -> Stream m b
c Stream m b
n -> (m a -> Stream m b -> Stream m b)
-> Stream m b -> Stream m a -> Stream m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(m a -> t m b -> t m b) -> t m b -> t m a -> t m b
foldrSMShared ((m b -> Stream m b -> Stream m b)
-> (a -> m b) -> m a -> Stream m b -> Stream m b
forall (m :: * -> *) b (t :: (* -> *) -> * -> *) a.
Monad m =>
(m b -> t m b -> t m b) -> (a -> m b) -> m a -> t m b -> t m b
mapMFB m b -> Stream m b -> Stream m b
c a -> m b
f) Stream m b
n Stream m a
xs)
instance Monad m => Functor (Stream m) where
fmap :: (a -> b) -> Stream m a -> Stream m b
fmap = (a -> b) -> Stream m a -> Stream m b
forall (t :: (* -> *) -> * -> *) a b (m :: * -> *).
IsStream t =>
(a -> b) -> t m a -> t m b
map
instance MonadTrans Stream where
{-# INLINE lift #-}
lift :: m a -> Stream m a
lift = m a -> Stream m a
forall (m :: * -> *) (t :: (* -> *) -> * -> *) a.
(Monad m, IsStream t) =>
m a -> t m a
fromEffect
{-# INLINE unShare #-}
unShare :: IsStream t => t m a -> t m a
unShare :: t m a -> t m a
unShare t m a
x = (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp t m a
x
{-# INLINE apWith #-}
apWith
:: IsStream t
=> (t m b -> t m b -> t m b)
-> t m (a -> b)
-> t m a
-> t m b
apWith :: (t m b -> t m b -> t m b) -> t m (a -> b) -> t m a -> t m b
apWith t m b -> t m b -> t m b
par t m (a -> b)
fstream t m a
stream = t m (a -> b) -> t m b
forall (t :: (* -> *) -> * -> *).
IsStream t =>
t m (a -> b) -> t m b
go1 t m (a -> b)
fstream
where
go1 :: t m (a -> b) -> t m b
go1 t m (a -> b)
m =
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b)
-> (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall a b. (a -> b) -> a -> b
$ \State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp ->
let foldShared :: t m b -> m r
foldShared = State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp
single :: (a -> b) -> m r
single a -> b
f = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a
unShare ((a -> b) -> t m a -> t m b
forall (t :: (* -> *) -> * -> *) (t :: (* -> *) -> * -> *) t a
(m :: * -> *).
(IsStream t, IsStream t) =>
(t -> a) -> t m t -> t m a
go2 a -> b
f t m a
stream)
yieldk :: (a -> b) -> t m (a -> b) -> m r
yieldk a -> b
f t m (a -> b)
r = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a
unShare ((a -> b) -> t m a -> t m b
forall (t :: (* -> *) -> * -> *) (t :: (* -> *) -> * -> *) t a
(m :: * -> *).
(IsStream t, IsStream t) =>
(t -> a) -> t m t -> t m a
go2 a -> b
f t m a
stream) t m b -> t m b -> t m b
`par` t m (a -> b) -> t m b
go1 t m (a -> b)
r
in State Stream m (a -> b)
-> ((a -> b) -> t m (a -> b) -> m r)
-> ((a -> b) -> m r)
-> m r
-> t m (a -> b)
-> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m b -> State Stream m (a -> b)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m b
st) (a -> b) -> t m (a -> b) -> m r
yieldk (a -> b) -> m r
single m r
stp t m (a -> b)
m
go2 :: (t -> a) -> t m t -> t m a
go2 t -> a
f t m t
m =
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
let single :: t -> m r
single t
a = a -> m r
sng (t -> a
f t
a)
yieldk :: t -> t m t -> m r
yieldk t
a t m t
r = a -> t m a -> m r
yld (t -> a
f t
a) ((t -> a) -> t m t -> t m a
go2 t -> a
f t m t
r)
in State Stream m t
-> (t -> t m t -> m r) -> (t -> m r) -> m r -> t m t -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m a -> State Stream m t
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m a
st) t -> t m t -> m r
yieldk t -> m r
single m r
stp t m t
m
{-# INLINE apSerial #-}
apSerial
:: IsStream t
=> t m (a -> b)
-> t m a
-> t m b
apSerial :: t m (a -> b) -> t m a -> t m b
apSerial t m (a -> b)
fstream t m a
stream = t m (a -> b) -> t m b
forall (t :: (* -> *) -> * -> *) (t :: (* -> *) -> * -> *) a.
(IsStream t, IsStream t) =>
t m (a -> a) -> t m a
go1 t m (a -> b)
fstream
where
go1 :: t m (a -> a) -> t m a
go1 t m (a -> a)
m =
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
let foldShared :: t m a -> m r
foldShared = State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp
single :: (a -> a) -> m r
single a -> a
f = t m a -> m r
foldShared (t m a -> m r) -> t m a -> m r
forall a b. (a -> b) -> a -> b
$ (a -> a) -> t m a -> t m a
forall (t :: (* -> *) -> * -> *) (t :: (* -> *) -> * -> *) t a
(m :: * -> *).
(IsStream t, IsStream t) =>
(t -> a) -> t m t -> t m a
go3 a -> a
f t m a
stream
yieldk :: (a -> a) -> t m (a -> a) -> m r
yieldk a -> a
f t m (a -> a)
r = t m a -> m r
foldShared (t m a -> m r) -> t m a -> m r
forall a b. (a -> b) -> a -> b
$ (a -> a) -> t m (a -> a) -> t m a -> t m a
go2 a -> a
f t m (a -> a)
r t m a
stream
in State Stream m (a -> a)
-> ((a -> a) -> t m (a -> a) -> m r)
-> ((a -> a) -> m r)
-> m r
-> t m (a -> a)
-> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m a -> State Stream m (a -> a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m a
st) (a -> a) -> t m (a -> a) -> m r
yieldk (a -> a) -> m r
single m r
stp t m (a -> a)
m
go2 :: (a -> a) -> t m (a -> a) -> t m a -> t m a
go2 a -> a
f t m (a -> a)
r1 t m a
m =
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
let foldShared :: t m a -> m r
foldShared = State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp
stop :: m r
stop = t m a -> m r
foldShared (t m a -> m r) -> t m a -> m r
forall a b. (a -> b) -> a -> b
$ t m (a -> a) -> t m a
go1 t m (a -> a)
r1
single :: a -> m r
single a
a = a -> t m a -> m r
yld (a -> a
f a
a) (t m (a -> a) -> t m a
go1 t m (a -> a)
r1)
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = a -> t m a -> m r
yld (a -> a
f a
a) ((a -> a) -> t m (a -> a) -> t m a -> t m a
go2 a -> a
f t m (a -> a)
r1 t m a
r)
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m a -> State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m a
st) a -> t m a -> m r
yieldk a -> m r
single m r
stop t m a
m
go3 :: (t -> a) -> t m t -> t m a
go3 t -> a
f t m t
m =
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
let single :: t -> m r
single t
a = a -> m r
sng (t -> a
f t
a)
yieldk :: t -> t m t -> m r
yieldk t
a t m t
r = a -> t m a -> m r
yld (t -> a
f t
a) ((t -> a) -> t m t -> t m a
go3 t -> a
f t m t
r)
in State Stream m t
-> (t -> t m t -> m r) -> (t -> m r) -> m r -> t m t -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m a -> State Stream m t
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m a
st) t -> t m t -> m r
yieldk t -> m r
single m r
stp t m t
m
{-# INLINE apSerialDiscardFst #-}
apSerialDiscardFst
:: IsStream t
=> t m a
-> t m b
-> t m b
apSerialDiscardFst :: t m a -> t m b -> t m b
apSerialDiscardFst t m a
fstream t m b
stream = t m a -> t m b
forall (t :: (* -> *) -> * -> *) p. IsStream t => t m p -> t m b
go1 t m a
fstream
where
go1 :: t m p -> t m b
go1 t m p
m =
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b)
-> (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall a b. (a -> b) -> a -> b
$ \State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp ->
let foldShared :: t m b -> m r
foldShared = State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp
single :: p -> m r
single p
_ = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m b
stream
yieldk :: p -> t m p -> m r
yieldk p
_ t m p
r = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m p -> t m b -> t m b
go2 t m p
r t m b
stream
in State Stream m p
-> (p -> t m p -> m r) -> (p -> m r) -> m r -> t m p -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m b -> State Stream m p
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m b
st) p -> t m p -> m r
forall p. p -> t m p -> m r
yieldk p -> m r
forall p. p -> m r
single m r
stp t m p
m
go2 :: t m p -> t m b -> t m b
go2 t m p
r1 t m b
m =
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b)
-> (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall a b. (a -> b) -> a -> b
$ \State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp ->
let foldShared :: t m b -> m r
foldShared = State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp
stop :: m r
stop = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m p -> t m b
go1 t m p
r1
single :: b -> m r
single b
a = b -> t m b -> m r
yld b
a (t m p -> t m b
go1 t m p
r1)
yieldk :: b -> t m b -> m r
yieldk b
a t m b
r = b -> t m b -> m r
yld b
a (t m p -> t m b -> t m b
go2 t m p
r1 t m b
r)
in State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m b
st b -> t m b -> m r
yieldk b -> m r
single m r
stop t m b
m
{-# INLINE apSerialDiscardSnd #-}
apSerialDiscardSnd
:: IsStream t
=> t m a
-> t m b
-> t m a
apSerialDiscardSnd :: t m a -> t m b -> t m a
apSerialDiscardSnd t m a
fstream t m b
stream = t m a -> t m a
forall (t :: (* -> *) -> * -> *) (t :: (* -> *) -> * -> *) a.
(IsStream t, IsStream t) =>
t m a -> t m a
go1 t m a
fstream
where
go1 :: t m a -> t m a
go1 t m a
m =
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
let foldShared :: t m a -> m r
foldShared = State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp
single :: a -> m r
single a
f = t m a -> m r
foldShared (t m a -> m r) -> t m a -> m r
forall a b. (a -> b) -> a -> b
$ a -> t m b -> t m a
forall (t :: (* -> *) -> * -> *) (t :: (* -> *) -> * -> *) a
(m :: * -> *) p.
(IsStream t, IsStream t) =>
a -> t m p -> t m a
go3 a
f t m b
stream
yieldk :: a -> t m a -> m r
yieldk a
f t m a
r = t m a -> m r
foldShared (t m a -> m r) -> t m a -> m r
forall a b. (a -> b) -> a -> b
$ a -> t m a -> t m b -> t m a
go2 a
f t m a
r t m b
stream
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream State Stream m a
st a -> t m a -> m r
yieldk a -> m r
single m r
stp t m a
m
go2 :: a -> t m a -> t m b -> t m a
go2 a
f t m a
r1 t m b
m =
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
let foldShared :: t m a -> m r
foldShared = State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp
stop :: m r
stop = t m a -> m r
foldShared (t m a -> m r) -> t m a -> m r
forall a b. (a -> b) -> a -> b
$ t m a -> t m a
go1 t m a
r1
single :: p -> m r
single p
_ = a -> t m a -> m r
yld a
f (t m a -> t m a
go1 t m a
r1)
yieldk :: p -> t m b -> m r
yieldk p
_ t m b
r = a -> t m a -> m r
yld a
f (a -> t m a -> t m b -> t m a
go2 a
f t m a
r1 t m b
r)
in State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m a -> State Stream m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m a
st) b -> t m b -> m r
forall p. p -> t m b -> m r
yieldk b -> m r
forall p. p -> m r
single m r
stop t m b
m
go3 :: a -> t m p -> t m a
go3 a
f t m p
m =
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a)
-> (forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
forall a b. (a -> b) -> a -> b
$ \State Stream m a
st a -> t m a -> m r
yld a -> m r
sng m r
stp ->
let single :: p -> m r
single p
_ = a -> m r
sng a
f
yieldk :: p -> t m p -> m r
yieldk p
_ t m p
r = a -> t m a -> m r
yld a
f (a -> t m p -> t m a
go3 a
f t m p
r)
in State Stream m p
-> (p -> t m p -> m r) -> (p -> m r) -> m r -> t m p -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m a -> State Stream m p
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m a
st) p -> t m p -> m r
forall p. p -> t m p -> m r
yieldk p -> m r
forall p. p -> m r
single m r
stp t m p
m
{-# INLINE bindWith #-}
bindWith
:: IsStream t
=> (t m b -> t m b -> t m b)
-> t m a
-> (a -> t m b)
-> t m b
bindWith :: (t m b -> t m b -> t m b) -> t m a -> (a -> t m b) -> t m b
bindWith t m b -> t m b -> t m b
par t m a
m1 a -> t m b
f = t m a -> t m b
forall (t :: (* -> *) -> * -> *). IsStream t => t m a -> t m b
go t m a
m1
where
go :: t m a -> t m b
go t m a
m =
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b)
-> (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall a b. (a -> b) -> a -> b
$ \State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp ->
let foldShared :: t m b -> m r
foldShared = State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp
single :: a -> m r
single a
a = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a
unShare (a -> t m b
f a
a)
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a
unShare (a -> t m b
f a
a) t m b -> t m b -> t m b
`par` t m a -> t m b
go t m a
r
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m b -> State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m b
st) a -> t m a -> m r
yieldk a -> m r
single m r
stp t m a
m
{-# INLINE concatMapBy #-}
concatMapBy
:: IsStream t
=> (t m b -> t m b -> t m b)
-> (a -> t m b)
-> t m a
-> t m b
concatMapBy :: (t m b -> t m b -> t m b) -> (a -> t m b) -> t m a -> t m b
concatMapBy t m b -> t m b -> t m b
par a -> t m b
f t m a
xs = (t m b -> t m b -> t m b) -> t m a -> (a -> t m b) -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) b a.
IsStream t =>
(t m b -> t m b -> t m b) -> t m a -> (a -> t m b) -> t m b
bindWith t m b -> t m b -> t m b
par t m a
xs a -> t m b
f
{-# INLINE concatMap #-}
concatMap :: IsStream t => (a -> t m b) -> t m a -> t m b
concatMap :: (a -> t m b) -> t m a -> t m b
concatMap a -> t m b
f t m a
m = Stream m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
Stream m a -> t m a
fromStream (Stream m b -> t m b) -> Stream m b -> t m b
forall a b. (a -> b) -> a -> b
$
(Stream m b -> Stream m b -> Stream m b)
-> (a -> Stream m b) -> Stream m a -> Stream m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) b a.
IsStream t =>
(t m b -> t m b -> t m b) -> (a -> t m b) -> t m a -> t m b
concatMapBy Stream m b -> Stream m b -> Stream m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a -> t m a
serial
(\a
a -> Stream m b -> Stream m b
forall (t1 :: (* -> *) -> * -> *) (t2 :: (* -> *) -> * -> *)
(m :: * -> *) a.
(IsStream t1, IsStream t2) =>
t1 m a -> t2 m a
adapt (Stream m b -> Stream m b) -> Stream m b -> Stream m b
forall a b. (a -> b) -> a -> b
$ t m b -> Stream m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> Stream m a
toStream (t m b -> Stream m b) -> t m b -> Stream m b
forall a b. (a -> b) -> a -> b
$ a -> t m b
f a
a)
(Stream m a -> Stream m a
forall (t1 :: (* -> *) -> * -> *) (t2 :: (* -> *) -> * -> *)
(m :: * -> *) a.
(IsStream t1, IsStream t2) =>
t1 m a -> t2 m a
adapt (Stream m a -> Stream m a) -> Stream m a -> Stream m a
forall a b. (a -> b) -> a -> b
$ t m a -> Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> Stream m a
toStream t m a
m)
{-# INLINE concatPairsWith #-}
concatPairsWith
:: IsStream t
=> (t m b -> t m b -> t m b)
-> (a -> t m b)
-> t m a
-> t m b
concatPairsWith :: (t m b -> t m b -> t m b) -> (a -> t m b) -> t m a -> t m b
concatPairsWith t m b -> t m b -> t m b
combine a -> t m b
f = Maybe a -> t m a -> t m b
forall (t :: (* -> *) -> * -> *).
IsStream t =>
Maybe a -> t m a -> t m b
go Maybe a
forall a. Maybe a
Nothing
where
go :: Maybe a -> t m a -> t m b
go Maybe a
Nothing t m a
stream =
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b)
-> (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall a b. (a -> b) -> a -> b
$ \State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp ->
let foldShared :: t m b -> m r
foldShared = State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp
single :: a -> m r
single a
a = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a
unShare (a -> t m b
f a
a)
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ Maybe a -> t m a -> t m b
go (a -> Maybe a
forall a. a -> Maybe a
Just a
a) t m a
r
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m b -> State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m b
st) a -> t m a -> m r
yieldk a -> m r
single m r
stp t m a
stream
go (Just a
a1) t m a
stream =
(forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b)
-> (forall r.
State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> m r)
-> t m b
forall a b. (a -> b) -> a -> b
$ \State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp ->
let foldShared :: t m b -> m r
foldShared = State Stream m b
-> (b -> t m b -> m r) -> (b -> m r) -> m r -> t m b -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m b
st b -> t m b -> m r
yld b -> m r
sng m r
stp
stop :: m r
stop = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a
unShare (a -> t m b
f a
a1)
single :: a -> m r
single a
a = t m b -> m r
foldShared (t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ t m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a
unShare (a -> t m b
f a
a1) t m b -> t m b -> t m b
`combine` a -> t m b
f a
a
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r =
t m b -> m r
foldShared
(t m b -> m r) -> t m b -> m r
forall a b. (a -> b) -> a -> b
$ (t m b -> t m b -> t m b)
-> ((t m b, t m b) -> t m b) -> t m (t m b, t m b) -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) b a.
IsStream t =>
(t m b -> t m b -> t m b) -> (a -> t m b) -> t m a -> t m b
concatPairsWith t m b -> t m b -> t m b
combine
(\(t m b
x,t m b
y) -> t m b -> t m b -> t m b
combine (t m b -> t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a -> t m a
unShare t m b
x) t m b
y)
(t m (t m b, t m b) -> t m b) -> t m (t m b, t m b) -> t m b
forall a b. (a -> b) -> a -> b
$ (a -> t m b
f a
a1, a -> t m b
f a
a) (t m b, t m b) -> t m (t m b, t m b) -> t m (t m b, t m b)
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
a -> t m a -> t m a
`cons` Maybe a -> t m a -> t m (t m b, t m b)
forall (t :: (* -> *) -> * -> *) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(IsStream t, IsStream t) =>
Maybe a -> t m a -> t m (t m b, t m b)
makePairs Maybe a
forall a. Maybe a
Nothing t m a
r
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m b -> State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m b
st) a -> t m a -> m r
forall (t :: (* -> *) -> * -> *). IsStream t => a -> t m a -> m r
yieldk a -> m r
single m r
stop t m a
stream
makePairs :: Maybe a -> t m a -> t m (t m b, t m b)
makePairs Maybe a
Nothing t m a
stream =
(forall r.
State Stream m (t m b, t m b)
-> ((t m b, t m b) -> t m (t m b, t m b) -> m r)
-> ((t m b, t m b) -> m r)
-> m r
-> m r)
-> t m (t m b, t m b)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m (t m b, t m b)
-> ((t m b, t m b) -> t m (t m b, t m b) -> m r)
-> ((t m b, t m b) -> m r)
-> m r
-> m r)
-> t m (t m b, t m b))
-> (forall r.
State Stream m (t m b, t m b)
-> ((t m b, t m b) -> t m (t m b, t m b) -> m r)
-> ((t m b, t m b) -> m r)
-> m r
-> m r)
-> t m (t m b, t m b)
forall a b. (a -> b) -> a -> b
$ \State Stream m (t m b, t m b)
st (t m b, t m b) -> t m (t m b, t m b) -> m r
yld (t m b, t m b) -> m r
sng m r
stp ->
let foldShared :: t m (t m b, t m b) -> m r
foldShared = State Stream m (t m b, t m b)
-> ((t m b, t m b) -> t m (t m b, t m b) -> m r)
-> ((t m b, t m b) -> m r)
-> m r
-> t m (t m b, t m b)
-> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStreamShared State Stream m (t m b, t m b)
st (t m b, t m b) -> t m (t m b, t m b) -> m r
yld (t m b, t m b) -> m r
sng m r
stp
single :: a -> m r
single a
a = (t m b, t m b) -> m r
sng (a -> t m b
f a
a, t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a
nil)
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = t m (t m b, t m b) -> m r
foldShared (t m (t m b, t m b) -> m r) -> t m (t m b, t m b) -> m r
forall a b. (a -> b) -> a -> b
$ Maybe a -> t m a -> t m (t m b, t m b)
makePairs (a -> Maybe a
forall a. a -> Maybe a
Just a
a) t m a
r
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m (t m b, t m b) -> State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m (t m b, t m b)
st) a -> t m a -> m r
yieldk a -> m r
single m r
stp t m a
stream
makePairs (Just a
a1) t m a
stream =
(forall r.
State Stream m (t m b, t m b)
-> ((t m b, t m b) -> t m (t m b, t m b) -> m r)
-> ((t m b, t m b) -> m r)
-> m r
-> m r)
-> t m (t m b, t m b)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
(forall r.
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> m r)
-> t m a
mkStream ((forall r.
State Stream m (t m b, t m b)
-> ((t m b, t m b) -> t m (t m b, t m b) -> m r)
-> ((t m b, t m b) -> m r)
-> m r
-> m r)
-> t m (t m b, t m b))
-> (forall r.
State Stream m (t m b, t m b)
-> ((t m b, t m b) -> t m (t m b, t m b) -> m r)
-> ((t m b, t m b) -> m r)
-> m r
-> m r)
-> t m (t m b, t m b)
forall a b. (a -> b) -> a -> b
$ \State Stream m (t m b, t m b)
st (t m b, t m b) -> t m (t m b, t m b) -> m r
yld (t m b, t m b) -> m r
sng m r
_ ->
let stop :: m r
stop = (t m b, t m b) -> m r
sng (a -> t m b
f a
a1, t m b
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
IsStream t =>
t m a
nil)
single :: a -> m r
single a
a = (t m b, t m b) -> m r
sng (a -> t m b
f a
a1, a -> t m b
f a
a)
yieldk :: a -> t m a -> m r
yieldk a
a t m a
r = (t m b, t m b) -> t m (t m b, t m b) -> m r
yld (a -> t m b
f a
a1, a -> t m b
f a
a) (Maybe a -> t m a -> t m (t m b, t m b)
makePairs Maybe a
forall a. Maybe a
Nothing t m a
r)
in State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a r.
IsStream t =>
State Stream m a
-> (a -> t m a -> m r) -> (a -> m r) -> m r -> t m a -> m r
foldStream (State Stream m (t m b, t m b) -> State Stream m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State Stream m (t m b, t m b)
st) a -> t m a -> m r
yieldk a -> m r
single m r
stop t m a
stream
instance Monad m => Applicative (Stream m) where
{-# INLINE pure #-}
pure :: a -> Stream m a
pure = a -> Stream m a
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
a -> t m a
fromPure
{-# INLINE (<*>) #-}
<*> :: Stream m (a -> b) -> Stream m a -> Stream m b
(<*>) = Stream m (a -> b) -> Stream m a -> Stream m b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap
instance Monad m => Monad (Stream m) where
{-# INLINE return #-}
return :: a -> Stream m a
return = a -> Stream m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE (>>=) #-}
>>= :: Stream m a -> (a -> Stream m b) -> Stream m b
(>>=) = ((a -> Stream m b) -> Stream m a -> Stream m b)
-> Stream m a -> (a -> Stream m b) -> Stream m b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> Stream m b) -> Stream m a -> Stream m b
forall (t :: (* -> *) -> * -> *) a (m :: * -> *) b.
IsStream t =>
(a -> t m b) -> t m a -> t m b
concatMap