Skip to content

Instantly share code, notes, and snippets.

@markwithers
Last active February 21, 2018 09:43
Show Gist options
  • Save markwithers/e55e660fe0c5288adfee7138a8e820a3 to your computer and use it in GitHub Desktop.
Save markwithers/e55e660fe0c5288adfee7138a8e820a3 to your computer and use it in GitHub Desktop.
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