@@ -17,6 +17,7 @@ module Asyncly.RunAsync
1717 , runAsyncly
1818 , toList
1919 , each
20+ , for
2021 , runAsynclyRecorded
2122-- , toListRecorded
2223 , playRecordings
@@ -30,6 +31,7 @@ import Control.Monad.Catch (MonadThrow)
3031import Control.Monad.IO.Class (MonadIO (..))
3132import Control.Monad.Trans.Class (MonadTrans (lift))
3233import Control.Monad.State (StateT(..), runStateT)
34+import Data.Monoid ((<>))
3335import Data.IORef (IORef, newIORef, readIORef)
3436
3537import Control.Monad.Trans.Recorder (MonadRecorder(..), RecorderT,
@@ -104,9 +106,15 @@ toList m = run Nothing m
104106 {-# INLINE run #-}
105107 run ctx mx = (runAsyncT mx) ctx stop yield
106108
109+-- | Run a given function concurrently on the list and collect the results.
110+{-# INLINABLE for #-}
111+for :: MonadAsync m => [a] -> (a -> AsyncT m b) -> AsynclyT m b
112+for xs f = foldr (<|>) empty $ map f xs
113+
114+-- XXX rename to fromList?
107115{-# INLINABLE each #-}
108116each :: MonadAsync m => [a] -> AsynclyT m a
109−each xs = foldr (<|>) empty $ map return xs
117+each xs = foldr (<>) empty $ map return xs
110118
111119------------------------------------------------------------------------------
112120-- Logging