on master help sign in
Add a doc note for map2 combinator for Unfolds
commit052936610fda41114faa0e220167a8402286b627 authorHarendra Kumar <harendra@composewell.com> dateTue 13 Dec 2022, 03:29 (4 years ago) parent30f69ab
1 file changed+7
core/src/Streamly/Internal/Data/Unfold/Type.hs+7
core/src/Streamly/Internal/Data/Unfold/Type.hs+7
@@ -317,10 +317,17 @@ mapM f (Unfold ustep uinject) = Unfold step uinject
317317 Skip s -> return $ Skip s
318318 Stop -> return Stop
319319
320+-- XXX We can also introduce a withInput combinator which will output the input
321+-- seed along with the output as a tuple.
322+
320323-- |
321324--
322325-- >>> map2 f = Unfold.mapM2 (\a b -> pure (f a b))
323326--
327+-- Note that the seed may mutate (e.g. if the seed is a Handle or IORef) as
328+-- stream is generated from it, so we need to be careful when reusing the seed
329+-- while the stream is being generated from it.
330+--
324331{-# INLINE_NORMAL map2 #-}
325332map2 :: Functor m => (a -> b -> c) -> Unfold m a b -> Unfold m a c
326333-- map2 f = mapM2 (\a b -> pure (f a b))