{-# LANGUAGE CPP #-}
module Streamly.Internal.Data.Stream.StreamD.Transform
(
transform
, map
, mapM
, sequence
, tap
, tapOffsetEvery
, trace
, trace_
, foldrS
, foldlS
, postscan
, scan
, scanMany
, splitOn
, scanlM'
, scanlMAfter'
, scanl'
, scanlM
, scanl
, scanl1M'
, scanl1'
, scanl1M
, scanl1
, prescanl'
, prescanlM'
, postscanl
, postscanlM
, postscanl'
, postscanlM'
, postscanlMAfter'
, postscanlx'
, postscanlMx'
, scanlMx'
, scanlx'
, with
, scanMaybe
, filter
, filterM
, deleteBy
, uniqBy
, uniq
, prune
, repeated
, take
, takeWhile
, takeWhileM
, takeWhileLast
, takeWhileAround
, drop
, dropWhile
, dropWhileM
, dropLast
, dropWhileLast
, dropWhileAround
, insertBy
, intersperse
, intersperseM
, intersperseMWith
, intersperseMSuffix
, intersperseMSuffixWith
, intersperseM_
, intersperseMSuffix_
, intersperseMPrefix_
, delay
, delayPre
, delayPost
, reverse
, reverseUnbox
, reassembleBy
, indexed
, indexedR
, timestampWith
, timestamped
, timeIndexWith
, timeIndexed
, findIndices
, elemIndices
, slicesBy
, rollingMap
, rollingMapM
, rollingMap2
, mapMaybe
, mapMaybeM
, catMaybes
, catLefts
, catRights
, catEithers
)
where
#include "inline.hs"
import Control.Concurrent (threadDelay)
import Control.Monad (void)
import Control.Monad.IO.Class (MonadIO (liftIO))
import Data.Either (fromLeft, isLeft, isRight, fromRight)
import Data.Functor ((<&>))
import Data.Maybe (fromJust, isJust)
import Fusion.Plugin.Types (Fuse(..))
import Streamly.Internal.Data.Fold.Type (Fold(..))
import Streamly.Internal.Data.Pipe.Type (Pipe(..), PipeState(..))
import Streamly.Internal.Data.SVar.Type (adaptState)
import Streamly.Internal.Data.Time.Units (AbsTime, RelTime64)
import Streamly.Internal.Data.Unboxed (Unbox)
import Streamly.Internal.System.IO (defaultChunkSize)
import qualified Streamly.Internal.Data.Array.Type as A
import qualified Streamly.Internal.Data.Fold as FL
import qualified Streamly.Internal.Data.Pipe.Type as Pipe
import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
import Prelude hiding
( drop, dropWhile, filter, map, mapM, reverse
, scanl, scanl1, sequence, take, takeWhile, zipWith)
import Streamly.Internal.Data.Stream.StreamD.Generate
(absTimesWith, relTimesWith)
import Streamly.Internal.Data.Stream.StreamD.Type
#include "DocTestDataStream.hs"
{-# INLINE_NORMAL transform #-}
transform :: Monad m => Pipe m a b -> Stream m a -> Stream m b
transform :: forall (m :: * -> *) a b.
Monad m =>
Pipe m a b -> Stream m a -> Stream m b
transform (Pipe s1 -> a -> m (Step (PipeState s1 s2) b)
pstep1 s2 -> m (Step (PipeState s1 s2) b)
pstep2 s1
pstate) (Stream State StreamK m a -> s -> m (Step s a)
step s
state) =
forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a
-> (PipeState s1 s2, s) -> m (Step (PipeState s1 s2, s) b)
step' (forall s1 s2. s1 -> PipeState s1 s2
Consume s1
pstate, s
state)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a
-> (PipeState s1 s2, s) -> m (Step (PipeState s1 s2, s) b)
step' State StreamK m a
gst (Consume s1
pst, s
st) = s1
pst seq :: forall a b. a -> b -> b
`seq` do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> do
Step (PipeState s1 s2) b
res <- s1 -> a -> m (Step (PipeState s1 s2) b)
pstep1 s1
pst a
x
case Step (PipeState s1 s2) b
res of
Pipe.Yield b
b PipeState s1 s2
pst' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
b (PipeState s1 s2
pst', s
s)
Pipe.Continue PipeState s1 s2
pst' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (PipeState s1 s2
pst', s
s)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s1 s2. s1 -> PipeState s1 s2
Consume s1
pst, s
s)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
_ (Produce s2
pst, s
st) = s2
pst seq :: forall a b. a -> b -> b
`seq` do
Step (PipeState s1 s2) b
res <- s2 -> m (Step (PipeState s1 s2) b)
pstep2 s2
pst
case Step (PipeState s1 s2) b
res of
Pipe.Yield b
b PipeState s1 s2
pst' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
b (PipeState s1 s2
pst', s
st)
Pipe.Continue PipeState s1 s2
pst' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (PipeState s1 s2
pst', s
st)
{-# INLINE_NORMAL foldlS #-}
foldlS :: Monad m
=> (Stream m b -> a -> Stream m b) -> Stream m b -> Stream m a -> Stream m b
foldlS :: forall (m :: * -> *) b a.
Monad m =>
(Stream m b -> a -> Stream m b)
-> Stream m b -> Stream m a -> Stream m b
foldlS Stream m b -> a -> Stream m b
fstep Stream m b
begin (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a
-> Either (s, Stream m b) (Stream m b)
-> m (Step (Either (s, Stream m b) (Stream m b)) b)
step' (forall a b. a -> Either a b
Left (s
state, Stream m b
begin))
where
step' :: State StreamK m a
-> Either (s, Stream m b) (Stream m b)
-> m (Step (Either (s, Stream m b) (Stream m b)) b)
step' State StreamK m a
gst (Left (s
st, Stream m b
acc)) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case Step s a
r of
Yield a
x s
s -> forall s a. s -> Step s a
Skip (forall a b. a -> Either a b
Left (s
s, Stream m b -> a -> Stream m b
fstep Stream m b
acc a
x))
Skip s
s -> forall s a. s -> Step s a
Skip (forall a b. a -> Either a b
Left (s
s, Stream m b
acc))
Step s a
Stop -> forall s a. s -> Step s a
Skip (forall a b. b -> Either a b
Right Stream m b
acc)
step' State StreamK m a
gst (Right (Stream State StreamK m b -> s -> m (Step s b)
stp s
stt)) = do
Step s b
r <- State StreamK m b -> s -> m (Step s b)
stp (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
stt
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case Step s b
r of
Yield b
x s
s -> forall s a. a -> s -> Step s a
Yield b
x (forall a b. b -> Either a b
Right (forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m b -> s -> m (Step s b)
stp s
s))
Skip s
s -> forall s a. s -> Step s a
Skip (forall a b. b -> Either a b
Right (forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m b -> s -> m (Step s b)
stp s
s))
Step s b
Stop -> forall s a. Step s a
Stop
{-# INLINE_NORMAL sequence #-}
sequence :: Monad m => Stream m (m a) -> Stream m a
sequence :: forall (m :: * -> *) a. Monad m => Stream m (m a) -> Stream m a
sequence (Stream State StreamK m (m a) -> s -> m (Step s (m a))
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}. State StreamK m a -> s -> m (Step s a)
step' s
state
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> s -> m (Step s a)
step' State StreamK m a
gst s
st = do
Step s (m a)
r <- State StreamK m (m a) -> s -> m (Step s (m a))
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s (m a)
r of
Yield m a
x s
s -> m a
x forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
a -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall s a. a -> s -> Step s a
Yield a
a s
s)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip s
s
Step s (m a)
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
data TapState fs st a
= TapInit | Tapping !fs st | TapDone st
{-# INLINE tap #-}
tap :: Monad m => Fold m a b -> Stream m a -> Stream m a
tap :: forall (m :: * -> *) a b.
Monad m =>
Fold m a b -> Stream m a -> Stream m a
tap (Fold s -> a -> m (Step s b)
fstep m (Step s b)
initial s -> m b
extract) (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {a} {a}.
State StreamK m a -> TapState s s a -> m (Step (TapState s s a) a)
step' forall fs st a. TapState fs st a
TapInit
where
step' :: State StreamK m a -> TapState s s a -> m (Step (TapState s s a) a)
step' State StreamK m a
_ TapState s s a
TapInit = do
Step s b
res <- m (Step s b)
initial
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> forall fs st a. fs -> st -> TapState fs st a
Tapping s
s s
state
FL.Done b
_ -> forall fs st a. st -> TapState fs st a
TapDone s
state
step' State StreamK m a
gst (Tapping s
acc s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> do
Step s b
res <- s -> a -> m (Step s b)
fstep s
acc a
x
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
fs -> forall fs st a. fs -> st -> TapState fs st a
Tapping s
fs s
s
FL.Done b
_ -> forall fs st a. st -> TapState fs st a
TapDone s
s
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall fs st a. fs -> st -> TapState fs st a
Tapping s
acc s
s)
Step s a
Stop -> do
forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ s -> m b
extract s
acc
forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
gst (TapDone s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s a
r of
Yield a
x s
s -> forall s a. a -> s -> Step s a
Yield a
x (forall fs st a. st -> TapState fs st a
TapDone s
s)
Skip s
s -> forall s a. s -> Step s a
Skip (forall fs st a. st -> TapState fs st a
TapDone s
s)
Step s a
Stop -> forall s a. Step s a
Stop
data TapOffState fs s a
= TapOffInit
| TapOffTapping !fs s Int
| TapOffDone s
{-# INLINE_NORMAL tapOffsetEvery #-}
tapOffsetEvery :: Monad m
=> Int -> Int -> Fold m a b -> Stream m a -> Stream m a
tapOffsetEvery :: forall (m :: * -> *) a b.
Monad m =>
Int -> Int -> Fold m a b -> Stream m a -> Stream m a
tapOffsetEvery Int
offset Int
n (Fold s -> a -> m (Step s b)
fstep m (Step s b)
initial s -> m b
extract) (Stream State StreamK m a -> s -> m (Step s a)
step s
state) =
forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {a} {a}.
State StreamK m a
-> TapOffState s s a -> m (Step (TapOffState s s a) a)
step' forall fs s a. TapOffState fs s a
TapOffInit
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a
-> TapOffState s s a -> m (Step (TapOffState s s a) a)
step' State StreamK m a
_ TapOffState s s a
TapOffInit = do
Step s b
res <- m (Step s b)
initial
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> forall fs s a. fs -> s -> Int -> TapOffState fs s a
TapOffTapping s
s s
state (Int
offset forall a. Integral a => a -> a -> a
`mod` Int
n)
FL.Done b
_ -> forall fs s a. s -> TapOffState fs s a
TapOffDone s
state
step' State StreamK m a
gst (TapOffTapping s
acc s
st Int
count) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> do
TapOffState s s a
next <-
if Int
count forall a. Ord a => a -> a -> Bool
<= Int
0
then do
Step s b
res <- s -> a -> m (Step s b)
fstep s
acc a
x
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
sres ->
forall fs s a. fs -> s -> Int -> TapOffState fs s a
TapOffTapping s
sres s
s (Int
n forall a. Num a => a -> a -> a
- Int
1)
FL.Done b
_ -> forall fs s a. s -> TapOffState fs s a
TapOffDone s
s
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall fs s a. fs -> s -> Int -> TapOffState fs s a
TapOffTapping s
acc s
s (Int
count forall a. Num a => a -> a -> a
- Int
1)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x TapOffState s s a
next
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall fs s a. fs -> s -> Int -> TapOffState fs s a
TapOffTapping s
acc s
s Int
count)
Step s a
Stop -> do
forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ s -> m b
extract s
acc
forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
gst (TapOffDone s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s a
r of
Yield a
x s
s -> forall s a. a -> s -> Step s a
Yield a
x (forall fs s a. s -> TapOffState fs s a
TapOffDone s
s)
Skip s
s -> forall s a. s -> Step s a
Skip (forall fs s a. s -> TapOffState fs s a
TapOffDone s
s)
Step s a
Stop -> forall s a. Step s a
Stop
{-# INLINE trace #-}
trace :: Monad m => (a -> m b) -> Stream m a -> Stream m a
trace :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Stream m a -> Stream m a
trace a -> m b
f = forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Stream m a -> Stream m b
mapM (\a
x -> forall (f :: * -> *) a. Functor f => f a -> f ()
void (a -> m b
f a
x) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return a
x)
{-# INLINE trace_ #-}
trace_ :: Monad m => m b -> Stream m a -> Stream m a
trace_ :: forall (m :: * -> *) b a.
Monad m =>
m b -> Stream m a -> Stream m a
trace_ m b
eff = forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Stream m a -> Stream m b
mapM (\a
x -> m b
eff forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return a
x)
data ScanState s f = ScanInit s | ScanDo s !f | ScanDone
{-# INLINE_NORMAL postscan #-}
postscan :: Monad m => FL.Fold m a b -> Stream m a -> Stream m b
postscan :: forall (m :: * -> *) a b.
Monad m =>
Fold m a b -> Stream m a -> Stream m b
postscan (FL.Fold s -> a -> m (Step s b)
fstep m (Step s b)
initial s -> m b
extract) (Stream State StreamK m a -> s -> m (Step s a)
sstep s
state) =
forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a -> ScanState s s -> m (Step (ScanState s s) b)
step (forall s f. s -> ScanState s f
ScanInit s
state)
where
{-# INLINE_LATE step #-}
step :: State StreamK m a -> ScanState s s -> m (Step (ScanState s s) b)
step State StreamK m a
_ (ScanInit s
st) = do
Step s b
res <- m (Step s b)
initial
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
fs -> forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall s f. s -> f -> ScanState s f
ScanDo s
st s
fs
FL.Done b
b -> forall s a. a -> s -> Step s a
Yield b
b forall s f. ScanState s f
ScanDone
step State StreamK m a
gst (ScanDo s
st s
fs) = do
Step s a
res <- State StreamK m a -> s -> m (Step s a)
sstep (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
res of
Yield a
x s
s -> do
Step s b
r <- s -> a -> m (Step s b)
fstep s
fs a
x
case Step s b
r of
FL.Partial s
fs1 -> do
!b
b <- s -> m b
extract s
fs1
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
b forall a b. (a -> b) -> a -> b
$ forall s f. s -> f -> ScanState s f
ScanDo s
s s
fs1
FL.Done b
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
b forall s f. ScanState s f
ScanDone
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall s f. s -> f -> ScanState s f
ScanDo s
s s
fs
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step State StreamK m a
_ ScanState s s
ScanDone = forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE scanWith #-}
scanWith :: Monad m
=> Bool -> Fold m a b -> Stream m a -> Stream m b
scanWith :: forall (m :: * -> *) a b.
Monad m =>
Bool -> Fold m a b -> Stream m a -> Stream m b
scanWith Bool
restart (Fold s -> a -> m (Step s b)
fstep m (Step s b)
initial s -> m b
extract) (Stream State StreamK m a -> s -> m (Step s a)
sstep s
state) =
forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a -> ScanState s s -> m (Step (ScanState s s) b)
step (forall s f. s -> ScanState s f
ScanInit s
state)
where
{-# INLINE runStep #-}
runStep :: s -> m (Step s b) -> m (Step (ScanState s s) b)
runStep s
st m (Step s b)
action = do
Step s b
res <- m (Step s b)
action
case Step s b
res of
FL.Partial s
fs -> do
!b
b <- s -> m b
extract s
fs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
b forall a b. (a -> b) -> a -> b
$ forall s f. s -> f -> ScanState s f
ScanDo s
st s
fs
FL.Done b
b ->
let next :: ScanState s f
next = if Bool
restart then forall s f. s -> ScanState s f
ScanInit s
st else forall s f. ScanState s f
ScanDone
in forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
b forall {f}. ScanState s f
next
{-# INLINE_LATE step #-}
step :: State StreamK m a -> ScanState s s -> m (Step (ScanState s s) b)
step State StreamK m a
_ (ScanInit s
st) = forall {s}. s -> m (Step s b) -> m (Step (ScanState s s) b)
runStep s
st m (Step s b)
initial
step State StreamK m a
gst (ScanDo s
st s
fs) = do
Step s a
res <- State StreamK m a -> s -> m (Step s a)
sstep (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
res of
Yield a
x s
s -> forall {s}. s -> m (Step s b) -> m (Step (ScanState s s) b)
runStep s
s (s -> a -> m (Step s b)
fstep s
fs a
x)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall s f. s -> f -> ScanState s f
ScanDo s
s s
fs
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step State StreamK m a
_ ScanState s s
ScanDone = forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE_NORMAL scan #-}
scan :: Monad m
=> FL.Fold m a b -> Stream m a -> Stream m b
scan :: forall (m :: * -> *) a b.
Monad m =>
Fold m a b -> Stream m a -> Stream m b
scan = forall (m :: * -> *) a b.
Monad m =>
Bool -> Fold m a b -> Stream m a -> Stream m b
scanWith Bool
False
{-# INLINE_NORMAL scanMany #-}
scanMany :: Monad m
=> FL.Fold m a b -> Stream m a -> Stream m b
scanMany :: forall (m :: * -> *) a b.
Monad m =>
Fold m a b -> Stream m a -> Stream m b
scanMany = forall (m :: * -> *) a b.
Monad m =>
Bool -> Fold m a b -> Stream m a -> Stream m b
scanWith Bool
True
{-# INLINE_NORMAL prescanlM' #-}
prescanlM' :: Monad m => (b -> a -> m b) -> m b -> Stream m a -> Stream m b
prescanlM' :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
prescanlM' b -> a -> m b
f m b
mz (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a -> (s, m b) -> m (Step (s, m b) b)
step' (s
state, m b
mz)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (s, m b) -> m (Step (s, m b) b)
step' State StreamK m a
gst (s
st, m b
prev) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> do
b
acc <- m b
prev
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
acc (s
s, b -> a -> m b
f b
acc a
x)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, m b
prev)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE prescanl' #-}
prescanl' :: Monad m => (b -> a -> b) -> b -> Stream m a -> Stream m b
prescanl' :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Stream m a -> Stream m b
prescanl' b -> a -> b
f b
z = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
prescanlM' (\b
a a
b -> forall (m :: * -> *) a. Monad m => a -> m a
return (b -> a -> b
f b
a a
b)) (forall (m :: * -> *) a. Monad m => a -> m a
return b
z)
{-# INLINE_NORMAL postscanlMx' #-}
postscanlMx' :: Monad m
=> (x -> a -> m x) -> m x -> (x -> m b) -> Stream m a -> Stream m b
postscanlMx' :: forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> m x) -> m x -> (x -> m b) -> Stream m a -> Stream m b
postscanlMx' x -> a -> m x
fstep m x
begin x -> m b
done (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = do
forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a -> (s, m x) -> m (Step (s, m x) b)
step' (s
state, m x
begin)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (s, m x) -> m (Step (s, m x) b)
step' State StreamK m a
gst (s
st, m x
acc) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> do
x
old <- m x
acc
x
y <- x -> a -> m x
fstep x
old a
x
b
v <- x -> m b
done x
y
b
v seq :: forall a b. a -> b -> b
`seq` x
y seq :: forall a b. a -> b -> b
`seq` forall (m :: * -> *) a. Monad m => a -> m a
return (forall s a. a -> s -> Step s a
Yield b
v (s
s, forall (m :: * -> *) a. Monad m => a -> m a
return x
y))
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, m x
acc)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE_NORMAL postscanlx' #-}
postscanlx' :: Monad m
=> (x -> a -> x) -> x -> (x -> b) -> Stream m a -> Stream m b
postscanlx' :: forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> x) -> x -> (x -> b) -> Stream m a -> Stream m b
postscanlx' x -> a -> x
fstep x
begin x -> b
done =
forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> m x) -> m x -> (x -> m b) -> Stream m a -> Stream m b
postscanlMx' (\x
b a
a -> forall (m :: * -> *) a. Monad m => a -> m a
return (x -> a -> x
fstep x
b a
a)) (forall (m :: * -> *) a. Monad m => a -> m a
return x
begin) (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> b
done)
{-# INLINE scanlMx' #-}
scanlMx' :: Monad m
=> (x -> a -> m x) -> m x -> (x -> m b) -> Stream m a -> Stream m b
scanlMx' :: forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> m x) -> m x -> (x -> m b) -> Stream m a -> Stream m b
scanlMx' x -> a -> m x
fstep m x
begin x -> m b
done Stream m a
s =
(m x
begin forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \x
x -> x
x seq :: forall a b. a -> b -> b
`seq` x -> m b
done x
x) forall (m :: * -> *) a.
Applicative m =>
m a -> Stream m a -> Stream m a
`consM` forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> m x) -> m x -> (x -> m b) -> Stream m a -> Stream m b
postscanlMx' x -> a -> m x
fstep m x
begin x -> m b
done Stream m a
s
{-# INLINE scanlx' #-}
scanlx' :: Monad m
=> (x -> a -> x) -> x -> (x -> b) -> Stream m a -> Stream m b
scanlx' :: forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> x) -> x -> (x -> b) -> Stream m a -> Stream m b
scanlx' x -> a -> x
fstep x
begin x -> b
done =
forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> m x) -> m x -> (x -> m b) -> Stream m a -> Stream m b
scanlMx' (\x
b a
a -> forall (m :: * -> *) a. Monad m => a -> m a
return (x -> a -> x
fstep x
b a
a)) (forall (m :: * -> *) a. Monad m => a -> m a
return x
begin) (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> b
done)
{-# INLINE_NORMAL postscanlM' #-}
postscanlM' :: Monad m => (b -> a -> m b) -> m b -> Stream m a -> Stream m b
postscanlM' :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
postscanlM' b -> a -> m b
fstep m b
begin (Stream State StreamK m a -> s -> m (Step s a)
step s
state) =
forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a -> Maybe (s, b) -> m (Step (Maybe (s, b)) b)
step' forall a. Maybe a
Nothing
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> Maybe (s, b) -> m (Step (Maybe (s, b)) b)
step' State StreamK m a
_ Maybe (s, b)
Nothing = do
!b
x <- m b
begin
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just (s
state, b
x))
step' State StreamK m a
gst (Just (s
st, b
acc)) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> do
!b
y <- b -> a -> m b
fstep b
acc a
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
y (forall a. a -> Maybe a
Just (s
s, b
y))
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just (s
s, b
acc))
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE_NORMAL postscanl' #-}
postscanl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
postscanl' :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Stream m a -> Stream m b
postscanl' a -> b -> a
f a
seed = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
postscanlM' (\a
a b
b -> forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b)) (forall (m :: * -> *) a. Monad m => a -> m a
return a
seed)
{-# ANN type PScanAfterState Fuse #-}
data PScanAfterState m st acc =
PScanAfterStep st (m acc)
| PScanAfterYield acc (PScanAfterState m st acc)
| PScanAfterStop
{-# INLINE_NORMAL postscanlMAfter' #-}
postscanlMAfter' :: Monad m
=> (b -> a -> m b) -> m b -> (b -> m b) -> Stream m a -> Stream m b
postscanlMAfter' :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> (b -> m b) -> Stream m a -> Stream m b
postscanlMAfter' b -> a -> m b
fstep m b
initial b -> m b
done (Stream State StreamK m a -> s -> m (Step s a)
step1 s
state1) = do
forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a
-> PScanAfterState m s b -> m (Step (PScanAfterState m s b) b)
step (forall (m :: * -> *) st acc.
st -> m acc -> PScanAfterState m st acc
PScanAfterStep s
state1 m b
initial)
where
{-# INLINE_LATE step #-}
step :: State StreamK m a
-> PScanAfterState m s b -> m (Step (PScanAfterState m s b) b)
step State StreamK m a
gst (PScanAfterStep s
st m b
acc) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step1 (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> do
!b
old <- m b
acc
!b
y <- b -> a -> m b
fstep b
old a
x
forall (m :: * -> *) a. Monad m => a -> m a
return (forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) st acc.
acc -> PScanAfterState m st acc -> PScanAfterState m st acc
PScanAfterYield b
y (forall (m :: * -> *) st acc.
st -> m acc -> PScanAfterState m st acc
PScanAfterStep s
s (forall (m :: * -> *) a. Monad m => a -> m a
return b
y)))
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) st acc.
st -> m acc -> PScanAfterState m st acc
PScanAfterStep s
s m b
acc
Step s a
Stop -> do
!b
v <- m b
acc
!b
res <- b -> m b
done b
v
forall (m :: * -> *) a. Monad m => a -> m a
return (forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) st acc.
acc -> PScanAfterState m st acc -> PScanAfterState m st acc
PScanAfterYield b
res forall (m :: * -> *) st acc. PScanAfterState m st acc
PScanAfterStop)
step State StreamK m a
_ (PScanAfterYield b
acc PScanAfterState m s b
next) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
acc PScanAfterState m s b
next
step State StreamK m a
_ PScanAfterState m s b
PScanAfterStop = forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE_NORMAL postscanlM #-}
postscanlM :: Monad m => (b -> a -> m b) -> m b -> Stream m a -> Stream m b
postscanlM :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
postscanlM b -> a -> m b
fstep m b
begin (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a -> Maybe (s, b) -> m (Step (Maybe (s, b)) b)
step' forall a. Maybe a
Nothing
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> Maybe (s, b) -> m (Step (Maybe (s, b)) b)
step' State StreamK m a
_ Maybe (s, b)
Nothing = do
b
r <- m b
begin
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just (s
state, b
r))
step' State StreamK m a
gst (Just (s
st, b
acc)) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> do
b
y <- b -> a -> m b
fstep b
acc a
x
forall (m :: * -> *) a. Monad m => a -> m a
return (forall s a. a -> s -> Step s a
Yield b
y (forall a. a -> Maybe a
Just (s
s, b
y)))
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just (s
s, b
acc))
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE_NORMAL postscanl #-}
postscanl :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
postscanl :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Stream m a -> Stream m b
postscanl a -> b -> a
f a
seed = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
postscanlM (\a
a b
b -> forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b)) (forall (m :: * -> *) a. Monad m => a -> m a
return a
seed)
{-# INLINE_NORMAL scanlM' #-}
scanlM' :: Monad m => (b -> a -> m b) -> m b -> Stream m a -> Stream m b
scanlM' :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
scanlM' b -> a -> m b
fstep m b
begin (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a -> Maybe (s, b) -> m (Step (Maybe (s, b)) b)
step' forall a. Maybe a
Nothing
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> Maybe (s, b) -> m (Step (Maybe (s, b)) b)
step' State StreamK m a
_ Maybe (s, b)
Nothing = do
!b
x <- m b
begin
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
x (forall a. a -> Maybe a
Just (s
state, b
x))
step' State StreamK m a
gst (Just (s
st, b
acc)) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> do
!b
y <- b -> a -> m b
fstep b
acc a
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
y (forall a. a -> Maybe a
Just (s
s, b
y))
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just (s
s, b
acc))
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE scanlMAfter' #-}
scanlMAfter' :: Monad m
=> (b -> a -> m b) -> m b -> (b -> m b) -> Stream m a -> Stream m b
scanlMAfter' :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> (b -> m b) -> Stream m a -> Stream m b
scanlMAfter' b -> a -> m b
fstep m b
initial b -> m b
done Stream m a
s =
m b
initial forall (m :: * -> *) a.
Applicative m =>
m a -> Stream m a -> Stream m a
`consM` forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> (b -> m b) -> Stream m a -> Stream m b
postscanlMAfter' b -> a -> m b
fstep m b
initial b -> m b
done Stream m a
s
{-# INLINE scanl' #-}
scanl' :: Monad m => (b -> a -> b) -> b -> Stream m a -> Stream m b
scanl' :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Stream m a -> Stream m b
scanl' b -> a -> b
f b
seed = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
scanlM' (\b
a a
b -> forall (m :: * -> *) a. Monad m => a -> m a
return (b -> a -> b
f b
a a
b)) (forall (m :: * -> *) a. Monad m => a -> m a
return b
seed)
{-# INLINE_NORMAL scanlM #-}
scanlM :: Monad m => (b -> a -> m b) -> m b -> Stream m a -> Stream m b
scanlM :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
scanlM b -> a -> m b
fstep m b
begin (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a -> Maybe (s, b) -> m (Step (Maybe (s, b)) b)
step' forall a. Maybe a
Nothing
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> Maybe (s, b) -> m (Step (Maybe (s, b)) b)
step' State StreamK m a
_ Maybe (s, b)
Nothing = do
b
x <- m b
begin
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
x (forall a. a -> Maybe a
Just (s
state, b
x))
step' State StreamK m a
gst (Just (s
st, b
acc)) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> do
b
y <- b -> a -> m b
fstep b
acc a
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
y (forall a. a -> Maybe a
Just (s
s, b
y))
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just (s
s, b
acc))
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE scanl #-}
scanl :: Monad m => (b -> a -> b) -> b -> Stream m a -> Stream m b
scanl :: forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Stream m a -> Stream m b
scanl b -> a -> b
f b
seed = forall (m :: * -> *) b a.
Monad m =>
(b -> a -> m b) -> m b -> Stream m a -> Stream m b
scanlM (\b
a a
b -> forall (m :: * -> *) a. Monad m => a -> m a
return (b -> a -> b
f b
a a
b)) (forall (m :: * -> *) a. Monad m => a -> m a
return b
seed)
{-# INLINE_NORMAL scanl1M #-}
scanl1M :: Monad m => (a -> a -> m a) -> Stream m a -> Stream m a
scanl1M :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> Stream m a
scanl1M a -> a -> m a
fstep (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a -> (s, Maybe a) -> m (Step (s, Maybe a) a)
step' (s
state, forall a. Maybe a
Nothing)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (s, Maybe a) -> m (Step (s, Maybe a) a)
step' State StreamK m a
gst (s
st, Maybe a
Nothing) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x (s
s, forall a. a -> Maybe a
Just a
x)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, forall a. Maybe a
Nothing)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
gst (s
st, Just a
acc) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
y s
s -> do
a
z <- a -> a -> m a
fstep a
acc a
y
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
z (s
s, forall a. a -> Maybe a
Just a
z)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, forall a. a -> Maybe a
Just a
acc)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE scanl1 #-}
scanl1 :: Monad m => (a -> a -> a) -> Stream m a -> Stream m a
scanl1 :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> a) -> Stream m a -> Stream m a
scanl1 a -> a -> a
f = forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> Stream m a
scanl1M (\a
x a
y -> forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a
f a
x a
y))
{-# INLINE_NORMAL scanl1M' #-}
scanl1M' :: Monad m => (a -> a -> m a) -> Stream m a -> Stream m a
scanl1M' :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> Stream m a
scanl1M' a -> a -> m a
fstep (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a -> (s, Maybe a) -> m (Step (s, Maybe a) a)
step' (s
state, forall a. Maybe a
Nothing)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (s, Maybe a) -> m (Step (s, Maybe a) a)
step' State StreamK m a
gst (s
st, Maybe a
Nothing) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> a
x seq :: forall a b. a -> b -> b
`seq` forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x (s
s, forall a. a -> Maybe a
Just a
x)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, forall a. Maybe a
Nothing)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
gst (s
st, Just a
acc) = a
acc seq :: forall a b. a -> b -> b
`seq` do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
y s
s -> do
a
z <- a -> a -> m a
fstep a
acc a
y
a
z seq :: forall a b. a -> b -> b
`seq` forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
z (s
s, forall a. a -> Maybe a
Just a
z)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, forall a. a -> Maybe a
Just a
acc)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE scanl1' #-}
scanl1' :: Monad m => (a -> a -> a) -> Stream m a -> Stream m a
scanl1' :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> a) -> Stream m a -> Stream m a
scanl1' a -> a -> a
f = forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> Stream m a
scanl1M' (\a
x a
y -> forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a
f a
x a
y))
{-# INLINE with #-}
with :: Monad m =>
(Stream m a -> Stream m (s, a))
-> (((s, a) -> b) -> Stream m (s, a) -> Stream m (s, a))
-> (((s, a) -> b) -> Stream m a -> Stream m a)
with :: forall (m :: * -> *) a s b.
Monad m =>
(Stream m a -> Stream m (s, a))
-> (((s, a) -> b) -> Stream m (s, a) -> Stream m (s, a))
-> ((s, a) -> b)
-> Stream m a
-> Stream m a
with Stream m a -> Stream m (s, a)
f ((s, a) -> b) -> Stream m (s, a) -> Stream m (s, a)
comb (s, a) -> b
g = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((s, a) -> b) -> Stream m (s, a) -> Stream m (s, a)
comb (s, a) -> b
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stream m a -> Stream m (s, a)
f
{-# INLINE_NORMAL filterM #-}
filterM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
filterM :: forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> Stream m a -> Stream m a
filterM a -> m Bool
f (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a -> s -> m (Step s a)
step' s
state
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> s -> m (Step s a)
step' State StreamK m a
gst s
st = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> do
Bool
b <- a -> m Bool
f a
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
b
then forall s a. a -> s -> Step s a
Yield a
x s
s
else forall s a. s -> Step s a
Skip s
s
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip s
s
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE filter #-}
filter :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
filter :: forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Stream m a -> Stream m a
filter a -> Bool
f = forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> Stream m a -> Stream m a
filterM (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
f)
{-# INLINE uniqBy #-}
uniqBy :: Monad m =>
(a -> a -> Bool) -> Stream m a -> Stream m a
uniqBy :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> Bool) -> Stream m a -> Stream m a
uniqBy a -> a -> Bool
eq = forall (m :: * -> *) a. Monad m => Stream m (Maybe a) -> Stream m a
catMaybes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
(Maybe a -> a -> b) -> Stream m a -> Stream m b
rollingMap Maybe a -> a -> Maybe a
f
where
f :: Maybe a -> a -> Maybe a
f Maybe a
pre a
curr =
case Maybe a
pre of
Maybe a
Nothing -> forall a. a -> Maybe a
Just a
curr
Just a
x -> if a
x a -> a -> Bool
`eq` a
curr then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just a
curr
{-# INLINE_NORMAL uniq #-}
uniq :: (Eq a, Monad m) => Stream m a -> Stream m a
uniq :: forall a (m :: * -> *). (Eq a, Monad m) => Stream m a -> Stream m a
uniq (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a -> (Maybe a, s) -> m (Step (Maybe a, s) a)
step' (forall a. Maybe a
Nothing, s
state)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (Maybe a, s) -> m (Step (Maybe a, s) a)
step' State StreamK m a
gst (Maybe a
Nothing, s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x (forall a. a -> Maybe a
Just a
x, s
s)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a. Maybe a
Nothing, s
s)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
gst (Just a
x, s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
y s
s | a
x forall a. Eq a => a -> a -> Bool
== a
y -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just a
x, s
s)
| Bool
otherwise -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
y (forall a. a -> Maybe a
Just a
y, s
s)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just a
x, s
s)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE_NORMAL deleteBy #-}
deleteBy :: Monad m => (a -> a -> Bool) -> a -> Stream m a -> Stream m a
deleteBy :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> Bool) -> a -> Stream m a -> Stream m a
deleteBy a -> a -> Bool
eq a
x (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a -> (s, Bool) -> m (Step (s, Bool) a)
step' (s
state, Bool
False)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (s, Bool) -> m (Step (s, Bool) a)
step' State StreamK m a
gst (s
st, Bool
False) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
y s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
if a -> a -> Bool
eq a
x a
y then forall s a. s -> Step s a
Skip (s
s, Bool
True) else forall s a. a -> s -> Step s a
Yield a
y (s
s, Bool
False)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, Bool
False)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
gst (s
st, Bool
True) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
y s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
y (s
s, Bool
True)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, Bool
True)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE prune #-}
prune ::
(a -> Bool) -> Stream m a -> Stream m a
prune :: forall a (m :: * -> *). (a -> Bool) -> Stream m a -> Stream m a
prune = forall a. HasCallStack => [Char] -> a
error [Char]
"Not implemented yet!"
repeated ::
Stream m a -> Stream m a
repeated :: forall (m :: * -> *) a. Stream m a -> Stream m a
repeated = forall a. HasCallStack => a
undefined
{-# INLINE takeWhileLast #-}
takeWhileLast ::
(a -> Bool) -> Stream m a -> Stream m a
takeWhileLast :: forall a (m :: * -> *). (a -> Bool) -> Stream m a -> Stream m a
takeWhileLast = forall a. HasCallStack => a
undefined
{-# INLINE takeWhileAround #-}
takeWhileAround ::
(a -> Bool) -> Stream m a -> Stream m a
takeWhileAround :: forall a (m :: * -> *). (a -> Bool) -> Stream m a -> Stream m a
takeWhileAround = forall a. HasCallStack => a
undefined
{-# INLINE_NORMAL drop #-}
drop :: Monad m => Int -> Stream m a -> Stream m a
drop :: forall (m :: * -> *) a. Monad m => Int -> Stream m a -> Stream m a
drop Int
n (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {a}.
(Ord a, Num a) =>
State StreamK m a -> (s, Maybe a) -> m (Step (s, Maybe a) a)
step' (s
state, forall a. a -> Maybe a
Just Int
n)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (s, Maybe a) -> m (Step (s, Maybe a) a)
step' State StreamK m a
gst (s
st, Just a
i)
| a
i forall a. Ord a => a -> a -> Bool
> a
0 = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
case Step s a
r of
Yield a
_ s
s -> forall s a. s -> Step s a
Skip (s
s, forall a. a -> Maybe a
Just (a
i forall a. Num a => a -> a -> a
- a
1))
Skip s
s -> forall s a. s -> Step s a
Skip (s
s, forall a. a -> Maybe a
Just a
i)
Step s a
Stop -> forall s a. Step s a
Stop
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
st, forall a. Maybe a
Nothing)
step' State StreamK m a
gst (s
st, Maybe a
Nothing) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
case Step s a
r of
Yield a
x s
s -> forall s a. a -> s -> Step s a
Yield a
x (s
s, forall a. Maybe a
Nothing)
Skip s
s -> forall s a. s -> Step s a
Skip (s
s, forall a. Maybe a
Nothing)
Step s a
Stop -> forall s a. Step s a
Stop
data DropWhileState s a
= DropWhileDrop s
| DropWhileYield a s
| DropWhileNext s
{-# INLINE_NORMAL dropWhileM #-}
dropWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
dropWhileM :: forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> Stream m a -> Stream m a
dropWhileM a -> m Bool
f (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {a}.
State StreamK m a
-> DropWhileState s a -> m (Step (DropWhileState s a) a)
step' (forall s a. s -> DropWhileState s a
DropWhileDrop s
state)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a
-> DropWhileState s a -> m (Step (DropWhileState s a) a)
step' State StreamK m a
gst (DropWhileDrop s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> do
Bool
b <- a -> m Bool
f a
x
if Bool
b
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s a. s -> DropWhileState s a
DropWhileDrop s
s)
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s a. a -> s -> DropWhileState s a
DropWhileYield a
x s
s)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s a. s -> DropWhileState s a
DropWhileDrop s
s)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
gst (DropWhileNext s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s a. a -> s -> DropWhileState s a
DropWhileYield a
x s
s)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s a. s -> DropWhileState s a
DropWhileNext s
s)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
_ (DropWhileYield a
x s
st) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x (forall s a. s -> DropWhileState s a
DropWhileNext s
st)
{-# INLINE dropWhile #-}
dropWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
dropWhile :: forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Stream m a -> Stream m a
dropWhile a -> Bool
f = forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> Stream m a -> Stream m a
dropWhileM (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
f)
{-# INLINE dropLast #-}
dropLast ::
Int -> Stream m a -> Stream m a
dropLast :: forall (m :: * -> *) a. Int -> Stream m a -> Stream m a
dropLast = forall a. HasCallStack => a
undefined
{-# INLINE dropWhileLast #-}
dropWhileLast ::
(a -> Bool) -> Stream m a -> Stream m a
dropWhileLast :: forall a (m :: * -> *). (a -> Bool) -> Stream m a -> Stream m a
dropWhileLast = forall a. HasCallStack => a
undefined
{-# INLINE dropWhileAround #-}
dropWhileAround ::
(a -> Bool) -> Stream m a -> Stream m a
dropWhileAround :: forall a (m :: * -> *). (a -> Bool) -> Stream m a -> Stream m a
dropWhileAround = forall a. HasCallStack => a
undefined
{-# INLINE_NORMAL insertBy #-}
insertBy :: Monad m => (a -> a -> Ordering) -> a -> Stream m a -> Stream m a
insertBy :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> Ordering) -> a -> Stream m a -> Stream m a
insertBy a -> a -> Ordering
cmp a
a (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a
-> (s, Bool, Maybe a) -> m (Step (s, Bool, Maybe a) a)
step' (s
state, Bool
False, forall a. Maybe a
Nothing)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a
-> (s, Bool, Maybe a) -> m (Step (s, Bool, Maybe a) a)
step' State StreamK m a
gst (s
st, Bool
False, Maybe a
_) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> case a -> a -> Ordering
cmp a
a a
x of
Ordering
GT -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x (s
s, Bool
False, forall a. Maybe a
Nothing)
Ordering
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
a (s
s, Bool
True, forall a. a -> Maybe a
Just a
x)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, Bool
False, forall a. Maybe a
Nothing)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
a (s
st, Bool
True, forall a. Maybe a
Nothing)
step' State StreamK m a
_ (s
_, Bool
True, Maybe a
Nothing) = forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
gst (s
st, Bool
True, Just a
prev) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
prev (s
s, Bool
True, forall a. a -> Maybe a
Just a
x)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, Bool
True, forall a. a -> Maybe a
Just a
prev)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
prev (s
st, Bool
True, forall a. Maybe a
Nothing)
data LoopState x s = FirstYield s
| InterspersingYield s
| YieldAndCarry x s
{-# INLINE_NORMAL intersperseM #-}
intersperseM :: Monad m => m a -> Stream m a -> Stream m a
intersperseM :: forall (m :: * -> *) a. Monad m => m a -> Stream m a -> Stream m a
intersperseM m a
m (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a -> LoopState a s -> m (Step (LoopState a s) a)
step' (forall x s. s -> LoopState x s
FirstYield s
state)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> LoopState a s -> m (Step (LoopState a s) a)
step' State StreamK m a
gst (FirstYield s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
case Step s a
r of
Yield a
x s
s -> forall s a. s -> Step s a
Skip (forall x s. x -> s -> LoopState x s
YieldAndCarry a
x s
s)
Skip s
s -> forall s a. s -> Step s a
Skip (forall x s. s -> LoopState x s
FirstYield s
s)
Step s a
Stop -> forall s a. Step s a
Stop
step' State StreamK m a
gst (InterspersingYield s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> do
a
a <- m a
m
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
a (forall x s. x -> s -> LoopState x s
YieldAndCarry a
x s
s)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall x s. s -> LoopState x s
InterspersingYield s
s
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step' State StreamK m a
_ (YieldAndCarry a
x s
st) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x (forall x s. s -> LoopState x s
InterspersingYield s
st)
{-# INLINE intersperse #-}
intersperse :: Monad m => a -> Stream m a -> Stream m a
intersperse :: forall (m :: * -> *) a. Monad m => a -> Stream m a -> Stream m a
intersperse a
a = forall (m :: * -> *) a. Monad m => m a -> Stream m a -> Stream m a
intersperseM (forall (m :: * -> *) a. Monad m => a -> m a
return a
a)
{-# INLINE_NORMAL intersperseM_ #-}
intersperseM_ :: Monad m => m b -> Stream m a -> Stream m a
intersperseM_ :: forall (m :: * -> *) b a.
Monad m =>
m b -> Stream m a -> Stream m a
intersperseM_ m b
m (Stream State StreamK m a -> s -> m (Step s a)
step1 s
state1) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a
-> Either (m (), s) s -> m (Step (Either (m (), s) s) a)
step (forall a b. a -> Either a b
Left (forall (f :: * -> *) a. Applicative f => a -> f a
pure (), s
state1))
where
{-# INLINE_LATE step #-}
step :: State StreamK m a
-> Either (m (), s) s -> m (Step (Either (m (), s) s) a)
step State StreamK m a
gst (Left (m ()
eff, s
st)) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step1 State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> m ()
eff forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (forall s a. a -> s -> Step s a
Yield a
x (forall a b. b -> Either a b
Right s
s))
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall a b. a -> Either a b
Left (m ()
eff, s
s))
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step State StreamK m a
_ (Right s
st) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall a b. a -> Either a b
Left (forall (f :: * -> *) a. Functor f => f a -> f ()
void m b
m, s
st)
{-# INLINE intersperseMWith #-}
intersperseMWith ::
Int -> m a -> Stream m a -> Stream m a
intersperseMWith :: forall (m :: * -> *) a. Int -> m a -> Stream m a -> Stream m a
intersperseMWith Int
_n m a
_f Stream m a
_xs = forall a. HasCallStack => a
undefined
data SuffixState s a
= SuffixElem s
| SuffixSuffix s
| SuffixYield a (SuffixState s a)
{-# INLINE_NORMAL intersperseMSuffix #-}
intersperseMSuffix :: forall m a. Monad m => m a -> Stream m a -> Stream m a
intersperseMSuffix :: forall (m :: * -> *) a. Monad m => m a -> Stream m a -> Stream m a
intersperseMSuffix m a
action (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a
-> SuffixState s a -> m (Step (SuffixState s a) a)
step' (forall s a. s -> SuffixState s a
SuffixElem s
state)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a
-> SuffixState s a -> m (Step (SuffixState s a) a)
step' State StreamK m a
gst (SuffixElem s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case Step s a
r of
Yield a
x s
s -> forall s a. s -> Step s a
Skip (forall s a. a -> SuffixState s a -> SuffixState s a
SuffixYield a
x (forall s a. s -> SuffixState s a
SuffixSuffix s
s))
Skip s
s -> forall s a. s -> Step s a
Skip (forall s a. s -> SuffixState s a
SuffixElem s
s)
Step s a
Stop -> forall s a. Step s a
Stop
step' State StreamK m a
_ (SuffixSuffix s
st) = do
m a
action forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
r -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s a. a -> SuffixState s a -> SuffixState s a
SuffixYield a
r (forall s a. s -> SuffixState s a
SuffixElem s
st))
step' State StreamK m a
_ (SuffixYield a
x SuffixState s a
next) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x SuffixState s a
next
{-# INLINE_NORMAL intersperseMSuffix_ #-}
intersperseMSuffix_ :: Monad m => m b -> Stream m a -> Stream m a
intersperseMSuffix_ :: forall (m :: * -> *) b a.
Monad m =>
m b -> Stream m a -> Stream m a
intersperseMSuffix_ m b
m (Stream State StreamK m a -> s -> m (Step s a)
step1 s
state1) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a -> Either s s -> m (Step (Either s s) a)
step (forall a b. a -> Either a b
Left s
state1)
where
{-# INLINE_LATE step #-}
step :: State StreamK m a -> Either s s -> m (Step (Either s s) a)
step State StreamK m a
gst (Left s
st) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step1 State StreamK m a
gst s
st
case Step s a
r of
Yield a
x s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x (forall a b. b -> Either a b
Right s
s)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall a b. a -> Either a b
Left s
s
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
step State StreamK m a
_ (Right s
st) = m b
m forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (forall s a. s -> Step s a
Skip (forall a b. a -> Either a b
Left s
st))
data SuffixSpanState s a
= SuffixSpanElem s Int
| SuffixSpanSuffix s
| SuffixSpanYield a (SuffixSpanState s a)
| SuffixSpanLast
| SuffixSpanStop
{-# INLINE_NORMAL intersperseMSuffixWith #-}
intersperseMSuffixWith :: forall m a. Monad m
=> Int -> m a -> Stream m a -> Stream m a
intersperseMSuffixWith :: forall (m :: * -> *) a.
Monad m =>
Int -> m a -> Stream m a -> Stream m a
intersperseMSuffixWith Int
n m a
action (Stream State StreamK m a -> s -> m (Step s a)
step s
state) =
forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream State StreamK m a
-> SuffixSpanState s a -> m (Step (SuffixSpanState s a) a)
step' (forall s a. s -> Int -> SuffixSpanState s a
SuffixSpanElem s
state Int
n)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a
-> SuffixSpanState s a -> m (Step (SuffixSpanState s a) a)
step' State StreamK m a
gst (SuffixSpanElem s
st Int
i) | Int
i forall a. Ord a => a -> a -> Bool
> Int
0 = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step State StreamK m a
gst s
st
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case Step s a
r of
Yield a
x s
s -> forall s a. s -> Step s a
Skip (forall s a. a -> SuffixSpanState s a -> SuffixSpanState s a
SuffixSpanYield a
x (forall s a. s -> Int -> SuffixSpanState s a
SuffixSpanElem s
s (Int
i forall a. Num a => a -> a -> a
- Int
1)))
Skip s
s -> forall s a. s -> Step s a
Skip (forall s a. s -> Int -> SuffixSpanState s a
SuffixSpanElem s
s Int
i)
Step s a
Stop -> if Int
i forall a. Eq a => a -> a -> Bool
== Int
n then forall s a. Step s a
Stop else forall s a. s -> Step s a
Skip forall s a. SuffixSpanState s a
SuffixSpanLast
step' State StreamK m a
_ (SuffixSpanElem s
st Int
_) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s a. s -> SuffixSpanState s a
SuffixSpanSuffix s
st)
step' State StreamK m a
_ (SuffixSpanSuffix s
st) = do
m a
action forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
r -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s a. a -> SuffixSpanState s a -> SuffixSpanState s a
SuffixSpanYield a
r (forall s a. s -> Int -> SuffixSpanState s a
SuffixSpanElem s
st Int
n))
step' State StreamK m a
_ SuffixSpanState s a
SuffixSpanLast = do
m a
action forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
r -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (forall s a. a -> SuffixSpanState s a -> SuffixSpanState s a
SuffixSpanYield a
r forall s a. SuffixSpanState s a
SuffixSpanStop)
step' State StreamK m a
_ (SuffixSpanYield a
x SuffixSpanState s a
next) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield a
x SuffixSpanState s a
next
step' State StreamK m a
_ SuffixSpanState s a
SuffixSpanStop = forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE intersperseMPrefix_ #-}
intersperseMPrefix_ :: Monad m => m b -> Stream m a -> Stream m a
intersperseMPrefix_ :: forall (m :: * -> *) b a.
Monad m =>
m b -> Stream m a -> Stream m a
intersperseMPrefix_ m b
m = forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Stream m a -> Stream m b
mapM (\a
x -> forall (f :: * -> *) a. Functor f => f a -> f ()
void m b
m forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return a
x)
{-# INLINE sleep #-}
sleep :: MonadIO m => Double -> m ()
sleep :: forall (m :: * -> *). MonadIO m => Double -> m ()
sleep Double
n = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Int -> IO ()
threadDelay forall a b. (a -> b) -> a -> b
$ forall a b. (RealFrac a, Integral b) => a -> b
round forall a b. (a -> b) -> a -> b
$ Double
n forall a. Num a => a -> a -> a
* Double
1000000
{-# INLINE delay #-}
delay :: MonadIO m => Double -> Stream m a -> Stream m a
delay :: forall (m :: * -> *) a.
MonadIO m =>
Double -> Stream m a -> Stream m a
delay = forall (m :: * -> *) b a.
Monad m =>
m b -> Stream m a -> Stream m a
intersperseM_ forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadIO m => Double -> m ()
sleep
{-# INLINE delayPost #-}
delayPost :: MonadIO m => Double -> Stream m a -> Stream m a
delayPost :: forall (m :: * -> *) a.
MonadIO m =>
Double -> Stream m a -> Stream m a
delayPost Double
n = forall (m :: * -> *) b a.
Monad m =>
m b -> Stream m a -> Stream m a
intersperseMSuffix_ forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Int -> IO ()
threadDelay forall a b. (a -> b) -> a -> b
$ forall a b. (RealFrac a, Integral b) => a -> b
round forall a b. (a -> b) -> a -> b
$ Double
n forall a. Num a => a -> a -> a
* Double
1000000
{-# INLINE delayPre #-}
delayPre :: MonadIO m => Double -> Stream m a -> Stream m a
delayPre :: forall (m :: * -> *) a.
MonadIO m =>
Double -> Stream m a -> Stream m a
delayPre = forall (m :: * -> *) b a.
Monad m =>
m b -> Stream m a -> Stream m a
intersperseMPrefix_forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadIO m => Double -> m ()
sleep
{-# INLINE_NORMAL reverse #-}
reverse :: Monad m => Stream m a -> Stream m a
reverse :: forall (m :: * -> *) a. Monad m => Stream m a -> Stream m a
reverse Stream m a
m = forall (m :: * -> *) a. Monad m => m (Stream m a) -> Stream m a
concatEffect forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
Monad m =>
Fold m a b -> Stream m a -> m b
fold forall (m :: * -> *) a. Monad m => Fold m a [a]
FL.toListRev Stream m a
m forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> forall (m :: * -> *) a. Applicative m => [a] -> Stream m a
fromList
{-# INLINE reverseUnbox #-}
reverseUnbox :: (MonadIO m, Unbox a) => Stream m a -> Stream m a
reverseUnbox :: forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m a -> Stream m a
reverseUnbox =
forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Stream m (Array a) -> Stream m a
A.flattenArraysRev
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Applicative m => StreamK m a -> Stream m a
fromStreamK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. StreamK m a -> StreamK m a
K.reverse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => Stream m a -> StreamK m a
toStreamK
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
(MonadIO m, Unbox a) =>
Int -> Stream m a -> Stream m (Array a)
A.chunksOf Int
defaultChunkSize
{-# INLINE reassembleBy #-}
reassembleBy
::
Fold m a b
-> (a -> a -> Int)
-> Stream m a
-> Stream m b
reassembleBy :: forall (m :: * -> *) a b.
Fold m a b -> (a -> a -> Int) -> Stream m a -> Stream m b
reassembleBy = forall a. HasCallStack => a
undefined
{-# INLINE_NORMAL indexed #-}
indexed :: Monad m => Stream m a -> Stream m (Int, a)
indexed :: forall (m :: * -> *) a. Monad m => Stream m a -> Stream m (Int, a)
indexed (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {b} {m :: * -> *} {a}.
Num b =>
State StreamK m a -> (s, b) -> m (Step (s, b) (b, a))
step' (s
state, Int
0)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (s, b) -> m (Step (s, b) (b, a))
step' State StreamK m a
gst (s
st, b
i) = b
i seq :: forall a b. a -> b -> b
`seq` do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield (b
i, a
x) (s
s, b
iforall a. Num a => a -> a -> a
+b
1)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, b
i)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE_NORMAL indexedR #-}
indexedR :: Monad m => Int -> Stream m a -> Stream m (Int, a)
indexedR :: forall (m :: * -> *) a.
Monad m =>
Int -> Stream m a -> Stream m (Int, a)
indexedR Int
m (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {b} {m :: * -> *} {a}.
Num b =>
State StreamK m a -> (s, b) -> m (Step (s, b) (b, a))
step' (s
state, Int
m)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (s, b) -> m (Step (s, b) (b, a))
step' State StreamK m a
gst (s
st, b
i) = b
i seq :: forall a b. a -> b -> b
`seq` do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s a
r of
Yield a
x s
s -> let i' :: b
i' = b
i forall a. Num a => a -> a -> a
- b
1
in forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield (b
i, a
x) (s
s, b
i')
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip (s
s, b
i)
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE timestampWith #-}
timestampWith :: (MonadIO m)
=> Double -> Stream m a -> Stream m (AbsTime, a)
timestampWith :: forall (m :: * -> *) a.
MonadIO m =>
Double -> Stream m a -> Stream m (AbsTime, a)
timestampWith Double
g Stream m a
stream = forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
zipWith (forall a b c. (a -> b -> c) -> b -> a -> c
flip (,)) Stream m a
stream (forall (m :: * -> *). MonadIO m => Double -> Stream m AbsTime
absTimesWith Double
g)
{-# INLINE timestamped #-}
timestamped :: (MonadIO m)
=> Stream m a -> Stream m (AbsTime, a)
timestamped :: forall (m :: * -> *) a.
MonadIO m =>
Stream m a -> Stream m (AbsTime, a)
timestamped = forall (m :: * -> *) a.
MonadIO m =>
Double -> Stream m a -> Stream m (AbsTime, a)
timestampWith Double
0.01
{-# INLINE timeIndexWith #-}
timeIndexWith :: (MonadIO m)
=> Double -> Stream m a -> Stream m (RelTime64, a)
timeIndexWith :: forall (m :: * -> *) a.
MonadIO m =>
Double -> Stream m a -> Stream m (RelTime64, a)
timeIndexWith Double
g Stream m a
stream = forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
zipWith (forall a b c. (a -> b -> c) -> b -> a -> c
flip (,)) Stream m a
stream (forall (m :: * -> *). MonadIO m => Double -> Stream m RelTime64
relTimesWith Double
g)
{-# INLINE timeIndexed #-}
timeIndexed :: (MonadIO m)
=> Stream m a -> Stream m (RelTime64, a)
timeIndexed :: forall (m :: * -> *) a.
MonadIO m =>
Stream m a -> Stream m (RelTime64, a)
timeIndexed = forall (m :: * -> *) a.
MonadIO m =>
Double -> Stream m a -> Stream m (RelTime64, a)
timeIndexWith Double
0.01
{-# INLINE_NORMAL findIndices #-}
findIndices :: Monad m => (a -> Bool) -> Stream m a -> Stream m Int
findIndices :: forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Stream m a -> Stream m Int
findIndices a -> Bool
p (Stream State StreamK m a -> s -> m (Step s a)
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {b} {m :: * -> *} {a}.
Num b =>
State StreamK m a -> (s, b) -> m (Step (s, b) b)
step' (s
state, Int
0)
where
{-# INLINE_LATE step' #-}
step' :: State StreamK m a -> (s, b) -> m (Step (s, b) b)
step' State StreamK m a
gst (s
st, b
i) = b
i seq :: forall a b. a -> b -> b
`seq` do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case Step s a
r of
Yield a
x s
s -> if a -> Bool
p a
x then forall s a. a -> s -> Step s a
Yield b
i (s
s, b
iforall a. Num a => a -> a -> a
+b
1) else forall s a. s -> Step s a
Skip (s
s, b
iforall a. Num a => a -> a -> a
+b
1)
Skip s
s -> forall s a. s -> Step s a
Skip (s
s, b
i)
Step s a
Stop -> forall s a. Step s a
Stop
{-# INLINE elemIndices #-}
elemIndices :: (Monad m, Eq a) => a -> Stream m a -> Stream m Int
elemIndices :: forall (m :: * -> *) a.
(Monad m, Eq a) =>
a -> Stream m a -> Stream m Int
elemIndices a
a = forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Stream m a -> Stream m Int
findIndices (forall a. Eq a => a -> a -> Bool
== a
a)
{-# INLINE_NORMAL slicesBy #-}
slicesBy :: Monad m => (a -> Bool) -> Stream m a -> Stream m (Int, Int)
slicesBy :: forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Stream m a -> Stream m (Int, Int)
slicesBy a -> Bool
p (Stream State StreamK m a -> s -> m (Step s a)
step1 s
state1) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {a} {m :: * -> *} {a}.
(Num a, Eq a) =>
State StreamK m a
-> Maybe (s, a, a) -> m (Step (Maybe (s, a, a)) (a, a))
step (forall a. a -> Maybe a
Just (s
state1, Int
0, Int
0))
where
{-# INLINE_LATE step #-}
step :: State StreamK m a
-> Maybe (s, a, a) -> m (Step (Maybe (s, a, a)) (a, a))
step State StreamK m a
gst (Just (s
st, a
i, a
len)) = a
i seq :: forall a b. a -> b -> b
`seq` a
len seq :: forall a b. a -> b -> b
`seq` do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step1 (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Step s a
r of
Yield a
x s
s ->
if a -> Bool
p a
x
then forall s a. a -> s -> Step s a
Yield (a
i, a
len forall a. Num a => a -> a -> a
+ a
1) (forall a. a -> Maybe a
Just (s
s, a
i forall a. Num a => a -> a -> a
+ a
len forall a. Num a => a -> a -> a
+ a
1, a
0))
else forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just (s
s, a
i, a
len forall a. Num a => a -> a -> a
+ a
1))
Skip s
s -> forall s a. s -> Step s a
Skip (forall a. a -> Maybe a
Just (s
s, a
i, a
len))
Step s a
Stop -> if a
len forall a. Eq a => a -> a -> Bool
== a
0 then forall s a. Step s a
Stop else forall s a. a -> s -> Step s a
Yield (a
i, a
len) forall a. Maybe a
Nothing
step State StreamK m a
_ Maybe (s, a, a)
Nothing = forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
data RollingMapState s a = RollingMapGo s a
{-# INLINE rollingMapM #-}
rollingMapM :: Monad m => (Maybe a -> a -> m b) -> Stream m a -> Stream m b
rollingMapM :: forall (m :: * -> *) a b.
Monad m =>
(Maybe a -> a -> m b) -> Stream m a -> Stream m b
rollingMapM Maybe a -> a -> m b
f (Stream State StreamK m a -> s -> m (Step s a)
step1 s
state1) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}.
State StreamK m a
-> RollingMapState s (Maybe a)
-> m (Step (RollingMapState s (Maybe a)) b)
step (forall s a. s -> a -> RollingMapState s a
RollingMapGo s
state1 forall a. Maybe a
Nothing)
where
step :: State StreamK m a
-> RollingMapState s (Maybe a)
-> m (Step (RollingMapState s (Maybe a)) b)
step State StreamK m a
gst (RollingMapGo s
s1 Maybe a
curr) = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
step1 (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
s1
case Step s a
r of
Yield a
x s
s -> do
!b
res <- Maybe a -> a -> m b
f Maybe a
curr a
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. a -> s -> Step s a
Yield b
res forall a b. (a -> b) -> a -> b
$ forall s a. s -> a -> RollingMapState s a
RollingMapGo s
s (forall a. a -> Maybe a
Just a
x)
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip forall a b. (a -> b) -> a -> b
$ forall s a. s -> a -> RollingMapState s a
RollingMapGo s
s Maybe a
curr
Step s a
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE rollingMap #-}
rollingMap :: Monad m => (Maybe a -> a -> b) -> Stream m a -> Stream m b
rollingMap :: forall (m :: * -> *) a b.
Monad m =>
(Maybe a -> a -> b) -> Stream m a -> Stream m b
rollingMap Maybe a -> a -> b
f = forall (m :: * -> *) a b.
Monad m =>
(Maybe a -> a -> m b) -> Stream m a -> Stream m b
rollingMapM (\Maybe a
x a
y -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Maybe a -> a -> b
f Maybe a
x a
y)
{-# INLINE rollingMap2 #-}
rollingMap2 :: Monad m => (a -> a -> b) -> Stream m a -> Stream m b
rollingMap2 :: forall (m :: * -> *) a b.
Monad m =>
(a -> a -> b) -> Stream m a -> Stream m b
rollingMap2 a -> a -> b
f = forall (m :: * -> *) a. Monad m => Stream m (Maybe a) -> Stream m a
catMaybes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
(Maybe a -> a -> b) -> Stream m a -> Stream m b
rollingMap Maybe a -> a -> Maybe b
g
where
g :: Maybe a -> a -> Maybe b
g Maybe a
Nothing a
_ = forall a. Maybe a
Nothing
g (Just a
x) a
y = forall a. a -> Maybe a
Just (a -> a -> b
f a
x a
y)
{-# INLINE_NORMAL mapMaybe #-}
mapMaybe :: Monad m => (a -> Maybe b) -> Stream m a -> Stream m b
mapMaybe :: forall (m :: * -> *) a b.
Monad m =>
(a -> Maybe b) -> Stream m a -> Stream m b
mapMaybe a -> Maybe b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. HasCallStack => Maybe a -> a
fromJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Stream m a -> Stream m a
filter forall a. Maybe a -> Bool
isJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> Stream m a -> Stream m b
map a -> Maybe b
f
{-# INLINE_NORMAL mapMaybeM #-}
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Stream m a -> Stream m b
mapMaybeM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m (Maybe b)) -> Stream m a -> Stream m b
mapMaybeM a -> m (Maybe b)
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. HasCallStack => Maybe a -> a
fromJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Stream m a -> Stream m a
filter forall a. Maybe a -> Bool
isJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Stream m a -> Stream m b
mapM a -> m (Maybe b)
f
{-# INLINE catMaybes #-}
catMaybes :: Monad m => Stream m (Maybe a) -> Stream m a
catMaybes :: forall (m :: * -> *) a. Monad m => Stream m (Maybe a) -> Stream m a
catMaybes (Stream State StreamK m (Maybe a) -> s -> m (Step s (Maybe a))
step s
state) = forall (m :: * -> *) a s.
(State StreamK m a -> s -> m (Step s a)) -> s -> Stream m a
Stream forall {m :: * -> *} {a}. State StreamK m a -> s -> m (Step s a)
step1 s
state
where
{-# INLINE_LATE step1 #-}
step1 :: State StreamK m a -> s -> m (Step s a)
step1 State StreamK m a
gst s
st = do
Step s (Maybe a)
r <- State StreamK m (Maybe a) -> s -> m (Step s (Maybe a))
step (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a (n :: * -> *) b.
State t m a -> State t n b
adaptState State StreamK m a
gst) s
st
case Step s (Maybe a)
r of
Yield Maybe a
x s
s -> do
forall (m :: * -> *) a. Monad m => a -> m a
return
forall a b. (a -> b) -> a -> b
$ case Maybe a
x of
Just a
a -> forall s a. a -> s -> Step s a
Yield a
a s
s
Maybe a
Nothing -> forall s a. s -> Step s a
Skip s
s
Skip s
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall s a. s -> Step s a
Skip s
s
Step s (Maybe a)
Stop -> forall (m :: * -> *) a. Monad m => a -> m a
return forall s a. Step s a
Stop
{-# INLINE scanMaybe #-}
scanMaybe :: Monad m => Fold m a (Maybe b) -> Stream m a -> Stream m b
scanMaybe :: forall (m :: * -> *) a b.
Monad m =>
Fold m a (Maybe b) -> Stream m a -> Stream m b
scanMaybe Fold m a (Maybe b)
f = forall (m :: * -> *) a. Monad m => Stream m (Maybe a) -> Stream m a
catMaybes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
Fold m a b -> Stream m a -> Stream m b
postscan Fold m a (Maybe b)
f
{-# INLINE catLefts #-}
catLefts :: Monad m => Stream m (Either a b) -> Stream m a
catLefts :: forall (m :: * -> *) a b.
Monad m =>
Stream m (Either a b) -> Stream m a
catLefts = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. a -> Either a b -> a
fromLeft forall a. HasCallStack => a
undefined) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Stream m a -> Stream m a
filter forall a b. Either a b -> Bool
isLeft
{-# INLINE catRights #-}
catRights :: Monad m => Stream m (Either a b) -> Stream m b
catRights :: forall (m :: * -> *) a b.
Monad m =>
Stream m (Either a b) -> Stream m b
catRights = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b a. b -> Either a b -> b
fromRight forall a. HasCallStack => a
undefined) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Stream m a -> Stream m a
filter forall a b. Either a b -> Bool
isRight
{-# INLINE catEithers #-}
catEithers :: Monad m => Stream m (Either a a) -> Stream m a
catEithers :: forall (m :: * -> *) a.
Monad m =>
Stream m (Either a a) -> Stream m a
catEithers = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. a -> a
id forall a. a -> a
id)
{-# INLINE splitOn #-}
splitOn :: Monad m => (a -> Bool) -> Fold m a b -> Stream m a -> Stream m b
splitOn :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Fold m a b -> Stream m a -> Stream m b
splitOn a -> Bool
predicate Fold m a b
f =
forall (m :: * -> *) a b.
Monad m =>
Fold m a b -> Stream m a -> Stream m b
foldManyPost (forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Fold m a b -> Fold m a b
FL.takeEndBy_ a -> Bool
predicate Fold m a b
f)