on master help sign in
Add the next API
bb195c2Harendra Kumar
src/Asyncly.hs+1
@@ -126,6 +126,7 @@ module Asyncly
126 -- * Running
126 -- * Running
127 , runAsyncly
127 , runAsyncly
128 , toList
128 , toList
129+ , next
129 , async
130 , async
130
131
131 -- * Monadic Composition (Conjunction)
132 -- * Monadic Composition (Conjunction)
src/Asyncly/AsyncT.hs+18−2
@@ -22,6 +22,7 @@ module Asyncly.AsyncT
22 , MonadAsync
22 , MonadAsync
23 , runAsyncly
23 , runAsyncly
24 , toList
24 , toList
25+ , next
25 , async
26 , async
26
27
27 , take
28 , take
@@ -691,6 +692,17 @@ toList m = (runAsyncT m) Nothing stop yield
691 yield a Nothing = return [a]
692 yield a Nothing = return [a]
692 yield a (Just x) = liftM (a :) (toList x)
693 yield a (Just x) = liftM (a :) (toList x)
693
694
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+
694------------------------------------------------------------------------------
706------------------------------------------------------------------------------
695-- Transformation
707-- Transformation
696------------------------------------------------------------------------------
708------------------------------------------------------------------------------
@@ -742,7 +754,9 @@ zipWith f m1 m2 = AsyncT $ \_ stp yld -> do
742 yield1 a (Just ra) = merge a ra
754 yield1 a (Just ra) = merge a ra
743 (runAsyncT m1) Nothing stp yield1
755 (runAsyncT m1) Nothing stp yield1
744
756
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.
746--
760--
747-- > f <$> ZipSerial xs1 <*> ... <*> ZipSerial xsN
761-- > f <$> ZipSerial xs1 <*> ... <*> ZipSerial xsN
748newtype ZipSerial m a = ZipSerial {getZipSerial :: AsyncT m a}
762newtype ZipSerial m a = ZipSerial {getZipSerial :: AsyncT m a}
@@ -797,7 +811,9 @@ zipAsyncWith f m1 m2 = AsyncT $ \_ stp yld -> do
797 mb <- async m2
811 mb <- async m2
798 (runAsyncT (zipWith f ma mb)) Nothing stp yld
812 (runAsyncT (zipWith f ma mb)) Nothing stp yld
799
813
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.
801--
817--
802-- > f <$> ZipAsync xs1 <*> ... <*> ZipAsync xsN
818-- > f <$> ZipAsync xs1 <*> ... <*> ZipAsync xsN
803newtype ZipAsync m a = ZipAsync {getZipAsync :: AsyncT m a}
819newtype ZipAsync m a = ZipAsync {getZipAsync :: AsyncT m a}