on master help sign in
rename operators
07c1357Harendra Kumar
examples/listdir.hs+1−1
@@ -13,5 +13,5 @@ main = runAsyncly $ getCurrentDir >>= readdir
13 liftIO $ mapM_ putStrLn $ map show fs ++ map show ds
13 liftIO $ mapM_ putStrLn $ map show fs ++ map show ds
14 --foldWith (<>) $ map readdir ds -- serial
14 --foldWith (<>) $ map readdir ds -- serial
15 --foldWith (<=>) $ map readdir ds -- serial interleaved
15 --foldWith (<=>) $ map readdir ds -- serial interleaved
16− foldWith (|>) $ map readdir ds -- concurrent left biased
16+ foldWith (<|) $ map readdir ds -- concurrent left biased
17 --foldWith (<|>) $ map readdir ds -- concurrent interleaved
17 --foldWith (<|>) $ map readdir ds -- concurrent interleaved
examples/map-reduce.hs+1−1
@@ -2,5 +2,5 @@ import Data.List (sum)
2import Asyncly
2import Asyncly
3
3
4main = do
4main = do
5− xs <- toList $ forEachWith (|>) [1..100] $ \x -> return (x * x) :: AsyncT IO Int
5+ xs <- toList $ forEachWith (<|) [1..100] $ \x -> return (x * x) :: AsyncT IO Int
6 print . sum $ xs
6 print . sum $ xs
src/Asyncly.hs+1−1
@@ -129,7 +129,7 @@ module Asyncly
129 , interleave
129 , interleave
130 , (<=>)
130 , (<=>)
131 , parLeft
131 , parLeft
132− , (|>)
132+ , (<|)
133 , foldWith
133 , foldWith
134 , foldMapWith
134 , foldMapWith
135 , forEachWith
135 , forEachWith
src/Asyncly/AsyncT.hs+14−12
@@ -24,9 +24,9 @@ module Asyncly.AsyncT
24 , interleave
24 , interleave
25 , (<=>)
25 , (<=>)
26 , parAhead
26 , parAhead
27− , (<>>)
27+ , (<>|)
28 , parLeft
28 , parLeft
29− , (|>)
29+ , (<|)
30 , foldWith
30 , foldWith
31 , foldMapWith
31 , foldMapWith
32 , forEachWith
32 , forEachWith
@@ -418,17 +418,19 @@ instance MonadAsync m => Alternative (AsyncT m) where
418 queueWork c m1 >> queueWork c m2
418 queueWork c m1 >> queueWork c m2
419 (runAsyncT (dequeueLoop c)) Nothing stp yld
419 (runAsyncT (dequeueLoop c)) Nothing stp yld
420
420
421+-- | Just like '<>' except that it can execute the action on the right in
421−-- | Run actions in parallel but return the results in serial order from left
422+-- parallel ahead of time. Returns the results in serial order like '<>' from
422−-- to right.
423+-- left to right.
423parAhead :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
424parAhead :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
424parAhead = undefined
425parAhead = undefined
425
426
426−(<>>) :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
427+(<>|) :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
427−(<>>) = parAhead
428+(<>|) = parAhead
428
429
429−-- | Left biased parallel execution. Actions are run in parallel but the
430+-- | Left biased parallel execution. Actions may run in parallel but not
430−-- the actions on the left are likely to be executed before those on
431+-- necessarily, the action on the left is executed before the one on the right
431−-- the right. This combinator is useful when fairness is not required.
432+-- when parallelism is not needed. This combinator is useful when fairness is
433+-- not required.
432{-# INLINE parLeft #-}
434{-# INLINE parLeft #-}
433parLeft :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
435parLeft :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
434parLeft m1 m2 = AsyncT $ \ctx stp yld -> do
436parLeft m1 m2 = AsyncT $ \ctx stp yld -> do
@@ -442,9 +444,9 @@ parLeft m1 m2 = AsyncT $ \ctx stp yld -> do
442 (runAsyncT (dequeueLoop c)) Nothing stp yld
444 (runAsyncT (dequeueLoop c)) Nothing stp yld
443
445
444-- | Same as 'parLeft'.
446-- | Same as 'parLeft'.
445−{-# INLINE (|>) #-}
447+{-# INLINE (<|) #-}
446−(|>) :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
448+(<|) :: MonadAsync m => AsyncT m a -> AsyncT m a -> AsyncT m a
447−(|>) = parLeft
449+(<|) = parLeft
448
450
449instance MonadAsync m => MonadPlus (AsyncT m) where
451instance MonadAsync m => MonadPlus (AsyncT m) where
450 mzero = empty
452 mzero = empty