on master help sign in
Add a scan skeleton for unfolds
commit7711796f5581a766fce58ab684ec08e76d803cce authorHarendra Kumar <harendra@composewell.com> dateThu 7 Oct 2021, 16:43 (5 years ago) parent5ed2212
1 file changed+16−20
src/Streamly/Internal/Data/Unfold.hs+16−20
src/Streamly/Internal/Data/Unfold.hs+16−20
@@ -110,11 +110,6 @@ module Streamly.Internal.Data.Unfold
110110 Step(..)
111111 , Unfold
112112
113− -- * Folding
114− , fold
115− , foldMany
116− -- pipe
117−
118113 -- * Unfolds
119114 -- One to one correspondence with
120115 -- "Streamly.Internal.Data.Stream.IsStream.Generate"
@@ -190,15 +185,20 @@ module Streamly.Internal.Data.Unfold
190185 , discardFirst
191186 , discardSecond
192187 , swap
193− , lscanlM'
194188 -- coapply
195189 -- comonad
196190
191+ -- * Folding
192+ , fold
193+
197194 -- ** Mapping on Output
198195 , map
199196 , mapM
200197 , mapMWithInput
201198 , scanlM'
199+ , scan
200+ , foldMany
201+ -- pipe
202202
203203 -- ** Either Wrapped Input
204204 , either
@@ -320,16 +320,6 @@ discardSecond = lmap fst
320320swap :: Unfold m (a, c) b -> Unfold m (c, a) b
321321swap = lmap Tuple.swap
322322
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−
333323-------------------------------------------------------------------------------
334324-- Output operations
335325-------------------------------------------------------------------------------
@@ -433,15 +423,21 @@ either (Unfold step1 inject1) = Unfold step inject
433423 Skip s -> Skip (s, f)
434424 Stop -> Stop) <$> step1 st
435425
436−-- See StreamD.scanlM' for implementing this.
426+-- See StreamD.scanOnce for implementing this.
437427--
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+
438435-- | Scan the output of an 'Unfold' to change it in a stateful manner.
439436--
440437-- /Unimplemented/
441438{-# INLINE_NORMAL scanlM' #-}
442−scanlM' :: -- Monad m =>
443− (b -> a -> m b) -> m b -> Unfold m c a -> Unfold m c b
444−scanlM' = undefined
439+scanlM' :: Monad m => (b -> a -> m b) -> m b -> Unfold m c a -> Unfold m c b
440+scanlM' f z = scan (FL.foldlM' f z)
445441
446442-------------------------------------------------------------------------------
447443-- Convert streams into unfolds