@@ -22,6 +22,7 @@ module Asyncly.AsyncT
2222 , MonadAsync
2323 , runAsyncly
2424 , toList
25+ , next
2526 , async
2627
2728 , take
@@ -691,6 +692,17 @@ toList m = (runAsyncT m) Nothing stop yield
691692 yield a Nothing = return [a]
692693 yield a (Just x) = liftM (a :) (toList x)
693694
695+next :: MonadAsync m => AsyncT m a -> m (Maybe (a, AsyncT m a))
696+next m = (runAsyncT m) Nothing stop yield
697+
698+ where
699+
700+ stop = return Nothing
701+
702+ {-# INLINE yield #-}
703+ yield a Nothing = return (Just (a, empty))
704+ yield a (Just x) = return (Just (a, x))
705+
694706------------------------------------------------------------------------------
695707-- Transformation
696708------------------------------------------------------------------------------
@@ -742,7 +754,9 @@ zipWith f m1 m2 = AsyncT $ \_ stp yld -> do
742754 yield1 a (Just ra) = merge a ra
743755 (runAsyncT m1) Nothing stp yield1
744756
745−-- | Wrapper around AsyncT type with a serial zipping Applicative instance
757+-- | Wrapper around AsyncT type with a serial zipping Applicative instance.
758+-- Note that the binary function interleave (<=>) is a special case of
759+-- ZipSerial Applicative.
746760--
747761-- > f <$> ZipSerial xs1 <*> ... <*> ZipSerial xsN
748762newtype ZipSerial m a = ZipSerial {getZipSerial :: AsyncT m a}
@@ -797,7 +811,9 @@ zipAsyncWith f m1 m2 = AsyncT $ \_ stp yld -> do
797811 mb <- async m2
798812 (runAsyncT (zipWith f ma mb)) Nothing stp yld
799813
800−-- | Wrapper around AsyncT type with a parallel zipping Applicative instance
814+-- | Wrapper around AsyncT type with a parallel zipping Applicative instance.
815+-- Note that the binary operator (<|>) from the Alternative instance of AsyncT
816+-- is a special case of ZipAsync Applicative.
801817--
802818-- > f <$> ZipAsync xs1 <*> ... <*> ZipAsync xsN
803819newtype ZipAsync m a = ZipAsync {getZipAsync :: AsyncT m a}