Last active
February 21, 2018 09:43
-
-
Save markwithers/e55e660fe0c5288adfee7138a8e820a3 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
const Future = require('fluture') | |
const Either = require('fantasy-eithers') | |
const r = require('ramda') | |
const lefts = r.reduce( | |
(memo, either) => { | |
let extract | |
either.bimap(x => extract = x, r.identity) | |
return extract ? r.append(extract, memo) : memo | |
}, | |
[] | |
) | |
const rights = r.reduce( | |
(memo, either) => { | |
let extract | |
either.bimap(r.identity, x => extract = x) | |
return extract ? r.append(extract, memo) : memo | |
}, | |
[] | |
) | |
var handleJobs = futures => | |
Future.parallel( | |
5, | |
futures.map(future => future.fold(Either.Left, Either.Right)) | |
) | |
.value(eithers => { | |
var successes = rights(eithers) | |
var failures = lefts(eithers) | |
console.log(successes, failures) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment