Skip to content

Instantly share code, notes, and snippets.

@bhurlow
Created November 18, 2019 20:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bhurlow/8ebbb2510f5d660d3541205ada7c1c14 to your computer and use it in GitHub Desktop.
Async Composition
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