on master help sign in
Add a scan skeleton for unfolds
7711796Harendra Kumar
src/Streamly/Internal/Data/Unfold.hs+16−20
@@ -110,11 +110,6 @@ module Streamly.Internal.Data.Unfold
110 Step(..)
110 Step(..)
111 , Unfold
111 , Unfold
112
112
113− -- * Folding
114− , fold
115− , foldMany
116− -- pipe
117−
118 -- * Unfolds
113 -- * Unfolds
119 -- One to one correspondence with
114 -- One to one correspondence with
120 -- "Streamly.Internal.Data.Stream.IsStream.Generate"
115 -- "Streamly.Internal.Data.Stream.IsStream.Generate"
@@ -190,15 +185,20 @@ module Streamly.Internal.Data.Unfold
190 , discardFirst
185 , discardFirst
191 , discardSecond
186 , discardSecond
192 , swap
187 , swap
193− , lscanlM'
194 -- coapply
188 -- coapply
195 -- comonad
189 -- comonad
196
190
191+ -- * Folding
192+ , fold
193+
197 -- ** Mapping on Output
194 -- ** Mapping on Output
198 , map
195 , map
199 , mapM
196 , mapM
200 , mapMWithInput
197 , mapMWithInput
201 , scanlM'
198 , scanlM'
199+ , scan
200+ , foldMany
201+ -- pipe
202
202
203 -- ** Either Wrapped Input
203 -- ** Either Wrapped Input
204 , either
204 , either
@@ -320,16 +320,6 @@ discardSecond = lmap fst
320swap :: Unfold m (a, c) b -> Unfold m (c, a) b
320swap :: Unfold m (a, c) b -> Unfold m (c, a) b
321swap = lmap Tuple.swap
321swap = lmap Tuple.swap
322
322
323−-- See StreamD.scanlM' for implementing this.
324−--
325−-- | Scan the input of an 'Unfold' to change it in a stateful manner.
326−--
327−-- /Unimplemented/
328−{-# INLINE_NORMAL lscanlM' #-}
329−lscanlM' :: -- Monad m =>
330− (b -> a -> m b) -> m b -> Unfold m b c -> Unfold m a c
331−lscanlM' = undefined
332−
333-------------------------------------------------------------------------------
323-------------------------------------------------------------------------------
334-- Output operations
324-- Output operations
335-------------------------------------------------------------------------------
325-------------------------------------------------------------------------------
@@ -433,15 +423,21 @@ either (Unfold step1 inject1) = Unfold step inject
433 Skip s -> Skip (s, f)
423 Skip s -> Skip (s, f)
434 Stop -> Stop) <$> step1 st
424 Stop -> Stop) <$> step1 st
435
425
436−-- See StreamD.scanlM' for implementing this.
426+-- See StreamD.scanOnce for implementing this.
437--
427--
428+-- | Scan the output of an 'Unfold' to change it in a stateful manner.
429+--
430+-- /Unimplemented/
431+{-# INLINE_NORMAL scan #-}
432+scan :: Fold m b c -> Unfold m a b -> Unfold m a c
433+scan = undefined
434+
438-- | Scan the output of an 'Unfold' to change it in a stateful manner.
435-- | Scan the output of an 'Unfold' to change it in a stateful manner.
439--
436--
440-- /Unimplemented/
437-- /Unimplemented/
441{-# INLINE_NORMAL scanlM' #-}
438{-# INLINE_NORMAL scanlM' #-}
442−scanlM' :: -- Monad m =>
443− (b -> a -> m b) -> m b -> Unfold m c a -> Unfold m c b
439+scanlM' :: Monad m => (b -> a -> m b) -> m b -> Unfold m c a -> Unfold m c b
444−scanlM' = undefined
440+scanlM' f z = scan (FL.foldlM' f z)
445
441
446-------------------------------------------------------------------------------
442-------------------------------------------------------------------------------
447-- Convert streams into unfolds
443-- Convert streams into unfolds