Created
November 18, 2019 20:12
-
-
Save bhurlow/8ebbb2510f5d660d3541205ada7c1c14 to your computer and use it in GitHub Desktop.
Async Composition
This file contains 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 R = require('ramda') | |
const maybeFoo = next => async item => { | |
console.log('maybeFoo', item) | |
item.data++ | |
return next(item) | |
} | |
const maybeBar = next => async item => { | |
console.log('maybeBar', item) | |
item.data++ | |
return next(item) | |
} | |
const maybeBaz = next => async item => { | |
console.log('maybeBaz', item) | |
item.data += 50 | |
return item | |
} | |
const LTI = R.compose(maybeFoo, maybeBar, maybeBaz) | |
const main = async () => { | |
const input = { data: 97 } | |
const root = item => { | |
return { | |
data: 'fallback' | |
} | |
} | |
const res = await LTI(root)(input) | |
console.log('res', res) | |
} | |
main().catch(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment