@@ -61,9 +61,9 @@ module Streamly.Internal.Data.Unfold
6161
6262 -- * Operations on Input
6363 , lmap
64− , close
65− , first
66− , second
64+ , supply
65+ , supplyFirst
66+ , supplySecond
6767 , discardFirst
6868 , discardSecond
6969 , swap
@@ -138,6 +138,9 @@ import qualified Streamly.Streams.StreamD as D
138138-- Input operations
139139-------------------------------------------------------------------------------
140140
141+-- | Map a function on the input argument of the 'Unfold'.
142+--
143+-- /Internal/
141144{-# INLINE_NORMAL lmap #-}
142145lmap :: (a -> c) -> Unfold m c b -> Unfold m a b
143146lmap f (Unfold ustep uinject) = Unfold ustep (uinject . f)
@@ -146,21 +149,19 @@ lmap f (Unfold ustep uinject) = Unfold ustep (uinject . f)
146149--
147150-- /Internal/
148151--
149−{-# INLINE_NORMAL close #-}
150−close :: Unfold m a b -> a -> Unfold m Void b
151−close unf a = lmap (const a) unf
152+{-# INLINE_NORMAL supply #-}
153+supply :: Unfold m a b -> a -> Unfold m Void b
154+supply unf a = lmap (const a) unf
152155
153−-- XXX rename to closeFst/closeSnd
154−--
155156-- | Supply the first component of the tuple to an unfold that accepts a tuple
156157-- as a seed resulting in a fold that accepts the second component of the tuple
157158-- as a seed.
158159--
159160-- /Internal/
160161--
161−{-# INLINE_NORMAL first #-}
162−first :: Unfold m (a, b) c -> a -> Unfold m b c
163−first unf a = lmap (a, ) unf
162+{-# INLINE_NORMAL supplyFirst #-}
163+supplyFirst :: Unfold m (a, b) c -> a -> Unfold m b c
164+supplyFirst unf a = lmap (a, ) unf
164165
165166-- | Supply the second component of the tuple to an unfold that accepts a tuple
166167-- as a seed resulting in a fold that accepts the first component of the tuple
@@ -168,18 +169,35 @@ first unf a = lmap (a, ) unf
168169--
169170-- /Internal/
170171--
171−{-# INLINE_NORMAL second #-}
172−second :: Unfold m (a, b) c -> b -> Unfold m a c
173−second unf b = lmap (, b) unf
172+{-# INLINE_NORMAL supplySecond #-}
173+supplySecond :: Unfold m (a, b) c -> b -> Unfold m a c
174+supplySecond unf b = lmap (, b) unf
174175
176+-- | Convert an 'Unfold' into an unfold accepting a tuple as an argument,
177+-- using the argument of the original fold as the second element of tuple and
178+-- discarding the first element of the tuple.
179+--
180+-- /Internal/
181+--
175182{-# INLINE_NORMAL discardFirst #-}
176183discardFirst :: Unfold m a b -> Unfold m (c, a) b
177184discardFirst = lmap snd
178185
186+-- | Convert an 'Unfold' into an unfold accepting a tuple as an argument,
187+-- using the argument of the original fold as the first element of tuple and
188+-- discarding the second element of the tuple.
189+--
190+-- /Internal/
191+--
179192{-# INLINE_NORMAL discardSecond #-}
180193discardSecond :: Unfold m a b -> Unfold m (a, c) b
181194discardSecond = lmap fst
182195
196+-- | Convert an 'Unfold' that accepts a tuple as an argument into an unfold
197+-- that accepts a tuple with elements swapped.
198+--
199+-- /Internal/
200+--
183201{-# INLINE_NORMAL swap #-}
184202swap :: Unfold m (a, c) b -> Unfold m (c, a) b
185203swap = lmap Tuple.swap
@@ -433,7 +451,7 @@ enumerateFromStepIntegral = Unfold step inject
433451{-# INLINE enumerateFromToIntegral #-}
434452enumerateFromToIntegral :: (Monad m, Integral a) => a -> Unfold m a a
435453enumerateFromToIntegral to =
436− takeWhile (<= to) $ second enumerateFromStepIntegral 1
454+ takeWhile (<= to) $ supplySecond enumerateFromStepIntegral 1
437455
438456{-# INLINE enumerateFromIntegral #-}
439457enumerateFromIntegral :: (Monad m, Integral a, Bounded a) => Unfold m a a
@@ -719,7 +737,7 @@ bracket bef aft (Unfold step1 inject1) = Unfold step inject
719737 Stop -> aft v >> return Stop
720738
721739-- | When unfolding if an exception occurs, unfold the exception using the
722−-- exception unfold.
740+-- exception unfold supplied as the first argument to 'handle'.
723741--
724742-- /Internal/
725743{-# INLINE_NORMAL handle #-}