on master help sign in
Remove redundant composition primitives

These can be simulated using a wait on an event and lifting/discarding the result.

commiteca7d81223dee57c786f787671f4a5e6e2459a01 authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 9 Aug 2017, 15:37 (9 years ago) parenta20c180
2 files changed+2−63
src/Asyncly.hs+1−9 src/Asyncly/AsyncT.hs+1−54
src/Asyncly.hs+1−9
@@ -137,19 +137,11 @@ module Asyncly
137137 , each
138138 --, gather
139139
140− -- * Compose
141− , before
142− , (*>>)
143− , thereafter
144− , (>>*)
145− , afterfirst
146− , (>>|)
147− -}
148−
149140 -- * Record and Play
150141 --, waitRecord
151142 --, waitRecord_
152143 --, playRecordings
144+-}
153145 )
154146where
155147
src/Asyncly/AsyncT.hs+1−54
@@ -25,22 +25,12 @@ module Asyncly.AsyncT
2525-- , async
2626-- , makeAsync
2727
28−{-
29− , before
30− , (*>>)
31− , thereafter
32− , (>>*)
33− , afterfirst
34− , (>>|)
35− -}
36−
3728 -- internal
3829 , dbg
3930 )
4031where
4132
4233import Control.Applicative (Alternative (..))
43−import Data.Maybe (maybe)
4434import Control.Monad (ap, mzero, when)
4535import Control.Monad.Base (MonadBase (..), liftBaseDefault)
4636import Control.Monad.Catch (MonadThrow, throwM)
@@ -52,6 +42,7 @@ import Control.Monad.Trans.Control (ComposeSt, MonadBaseControl (..),
5242 MonadTransControl (..),
5343 defaultLiftBaseWith,
5444 defaultRestoreM, liftBaseWith)
45+import Data.Maybe (maybe)
5546import Data.IORef (newIORef, readIORef, writeIORef)
5647import Unsafe.Coerce (unsafeCoerce)
5748
@@ -213,50 +204,6 @@ instance (MonadAsync m, MonadRecorder m) => MonadRecorder (AsyncT m) where
213204 putJournal = lift . putJournal
214205 play = lift . play
215206
216−------------------------------------------------------------------------------
217−-- Special compositions
218−------------------------------------------------------------------------------
219−
220−{-
221−-- | Run @m a@ before running @m b@. The result of @m a@ is discarded.
222−before :: MonadAsync m => AsyncT m a -> AsyncT m b -> AsyncT m b
223−before ma mb = AsyncT $ \stp yld ->
224− (runAsyncT ma) ((runAsyncT mb) stp yld) yld
225−
226−infixr 1 *>>
227−-- | Same as 'before'.
228−(*>>) :: MonadAsync m => AsyncT m a -> AsyncT m b -> AsyncT m b
229−(*>>) = before
230−
231−-- | Run @m b@ after running @m a@. The result of @m b@ is discarded.
232−thereafter :: MonadAsync m => AsyncT m a -> AsyncT m b -> AsyncT m a
233−thereafter ma mb = AsyncT $ do
234− a <- runAsyncT ma
235− _ <- runAsyncT (mb >> mzero)
236− return a
237−
238−infixr 1 >>*
239−-- | Same as 'thereafter'.
240−(>>*) :: MonadAsync m => AsyncT m a -> AsyncT m b -> AsyncT m a
241−(>>*) = thereafter
242−
243−-- XXX This can be moved to utility functions as it is purely app level
244−-- | Run @m b@ right after the first event in @m a@ is generated but before it
245−-- is yielded. The result of @m b@ is discarded.
246−afterfirst :: MonadAsync m => AsyncT m a -> AsyncT m b -> AsyncT m a
247−afterfirst ma mb = do
248− ref <- liftIO $ newIORef False
249− x <- ma
250− done <- liftIO $ readIORef ref
251− when (not done) $ (liftIO $ writeIORef ref True) >>* mb
252− return x
253−
254−infixr 1 >>|
255−-- | Same as 'afterfirst'.
256−(>>|) :: MonadAsync m => AsyncT m a -> AsyncT m b -> AsyncT m a
257−(>>|) = afterfirst
258−-}
259−
260207------------------------------------------------------------------------------
261208-- Async primitives
262209------------------------------------------------------------------------------