@@ -24,6 +24,7 @@ module Asyncly.AsyncT
2424 , toList
2525 , uncons
2626 , async
27+ , unfoldr
2728
2829 , take
2930 , drop
@@ -717,6 +718,16 @@ uncons m = (runAsyncT m) Nothing stop yield
717718 yield a Nothing = return (Just (a, empty))
718719 yield a (Just x) = return (Just (a, x))
719720
721+-- | Build a Stream by unfolding steps starting from a seed.
722+unfoldr :: MonadAsync m => (b -> m (Maybe (a, b))) -> b -> AsyncT m a
723+unfoldr step = go
724+ where
725+ go s = AsyncT $ \_ stp yld -> do
726+ mayb <- step s
727+ case mayb of
728+ Nothing -> stp
729+ Just (a, b) -> yld a (Just (go b))
730+
720731------------------------------------------------------------------------------
721732-- Transformation
722733------------------------------------------------------------------------------
@@ -769,7 +780,7 @@ zipWith f m1 m2 = AsyncT $ \_ stp yld -> do
769780 (runAsyncT m1) Nothing stp yield1
770781
771782-- | Wrapper around AsyncT type with a serial zipping Applicative instance.
772−-- Note that the binary function interleave (<=>) is a special case of
783+-- Note that the binary function interleave (\<=>) is a special case of
773784-- ZipSerial Applicative.
774785--
775786-- > f <$> ZipSerial xs1 <*> ... <*> ZipSerial xsN
@@ -835,7 +846,7 @@ zipAsyncWith f m1 m2 = AsyncT $ \_ stp yld -> do
835846 (runAsyncT (zipWith f ma mb)) Nothing stp yld
836847
837848-- | Wrapper around AsyncT type with a parallel zipping Applicative instance.
838−-- Note that the binary operator (<|>) from the Alternative instance of AsyncT
849+-- Note that the binary operator (\<|>) from the Alternative instance of AsyncT
839850-- is a special case of ZipAsync Applicative.
840851--
841852-- > f <$> ZipAsync xs1 <*> ... <*> ZipAsync xsN