Last active
August 29, 2015 14:07
-
-
Save ifesdjeen/1686093459101d674d9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Concurrent.ParallelIO.Global (parallel) | |
import Control.Arrow (left) | |
data DbError = DbError | |
data Input = Input | |
data Result = Result | |
someOperation :: Either DbError [Input] | |
-> (Input -> IO (Either DbError Result)) | |
-> IO (Either DbError [Result]) | |
someOperation (Left err) op = return $ Left err | |
someOperation (Right inputs) op = do | |
res <- parallel $ map op inputs | |
return $ sequence res | |
-- Another variation | |
someOperation eitherInputs op = left eitherInputs \inputs -> do | |
res <- parallel $ map op inputs | |
return $ sequence res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Somehow I think
async
package is more practical at concurrent/parallel things, using itsmapConcurrently
function.The fact that
someOperation
carries a callbackInput -> IO (Either DbError Result)
shows that same callback should have been applied upfront.Your
Input
processing should look like this:I imagine you need something like this at some point:
The thing is, you want
doingStuffWithInput
to be executed in parallel. Alright:And you've done