on master help sign in
Add an "unfoldr" unfold
commitea6f2fb6be32d767a7ec570b448c3f0f5c3ffa70 authorHarendra Kumar <harendra@composewell.com> dateThu 25 Mar 2021, 02:54 (6 years ago) parentae741f1
3 files changed+11
src/Streamly/Data/Unfold.hs+1 src/Streamly/Internal/Data/Unfold.hs+1 src/Streamly/Internal/Data/Unfold/Type.hs+9
src/Streamly/Data/Unfold.hs+1
@@ -65,6 +65,7 @@ module Streamly.Data.Unfold
6565
6666 -- ** Basic Constructors
6767 , unfoldrM
68+ , unfoldr
6869 , function
6970 , functionM
7071
src/Streamly/Internal/Data/Unfold.hs+1
@@ -89,6 +89,7 @@ module Streamly.Internal.Data.Unfold
8989 , mkUnfoldM
9090 , mkUnfoldrM
9191 , unfoldrM
92+ , unfoldr
9293 , functionM
9394 , function
9495 , identity
src/Streamly/Internal/Data/Unfold/Type.hs+9
@@ -13,6 +13,7 @@ module Streamly.Internal.Data.Unfold.Type
1313 , mkUnfoldM
1414 , mkUnfoldrM
1515 , unfoldrM
16+ , unfoldr
1617 , functionM
1718 , function
1819 , identity
@@ -118,6 +119,14 @@ unfoldrM next = Unfold step pure
118119 Just (x, s) -> Yield x s
119120 Nothing -> Stop) <$> next st
120121
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+
121130------------------------------------------------------------------------------
122131-- Map input
123132------------------------------------------------------------------------------