on master help sign in
Add an "unfoldr" unfold
ea6f2fbHarendra Kumar
src/Streamly/Data/Unfold.hs+1
@@ -65,6 +65,7 @@ module Streamly.Data.Unfold
65
65
66 -- ** Basic Constructors
66 -- ** Basic Constructors
67 , unfoldrM
67 , unfoldrM
68+ , unfoldr
68 , function
69 , function
69 , functionM
70 , functionM
70
71
src/Streamly/Internal/Data/Unfold.hs+1
@@ -89,6 +89,7 @@ module Streamly.Internal.Data.Unfold
89 , mkUnfoldM
89 , mkUnfoldM
90 , mkUnfoldrM
90 , mkUnfoldrM
91 , unfoldrM
91 , unfoldrM
92+ , unfoldr
92 , functionM
93 , functionM
93 , function
94 , function
94 , identity
95 , identity
src/Streamly/Internal/Data/Unfold/Type.hs+9
@@ -13,6 +13,7 @@ module Streamly.Internal.Data.Unfold.Type
13 , mkUnfoldM
13 , mkUnfoldM
14 , mkUnfoldrM
14 , mkUnfoldrM
15 , unfoldrM
15 , unfoldrM
16+ , unfoldr
16 , functionM
17 , functionM
17 , function
18 , function
18 , identity
19 , identity
@@ -118,6 +119,14 @@ unfoldrM next = Unfold step pure
118 Just (x, s) -> Yield x s
119 Just (x, s) -> Yield x s
119 Nothing -> Stop) <$> next st
120 Nothing -> Stop) <$> next st
120
121
122+-- | Like 'unfoldrM' but uses a pure step function.
123+--
124+-- /Pre-release/
125+--
126+{-# INLINE unfoldr #-}
127+unfoldr :: Applicative m => (a -> Maybe (b, a)) -> Unfold m a b
128+unfoldr step = unfoldrM (pure . step)
129+
121------------------------------------------------------------------------------
130------------------------------------------------------------------------------
122-- Map input
131-- Map input
123------------------------------------------------------------------------------
132------------------------------------------------------------------------------