Skip to content

Instantly share code, notes, and snippets.

@victorvoid victorvoid/composability-example08.js Secret

Last active Aug 20, 2018
Embed
What would you like to do?
const IO = f => ({
runIO: f,
map: g =>
IO(() => g(f())),
chain: g =>
IO(g(f()).runIO)
})
const log = label => x =>
IO(() => (console.log(label, x), x))
const $ = x =>
IO(() => document.querySelector(x))
const getText = e =>
e.textContent
const main = selector =>
$(selector)
.map(getText)
.chain(log('A'))
.map(s => s.toUpperCase())
.chain(log('B'))
.runIO()
main('title')
// A hello world
// B HELLO WORLD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.