Skip to content

Instantly share code, notes, and snippets.

@victorvoid
Last active August 20, 2018 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorvoid/71558bc5921a4fcb48c6b585bfc97b73 to your computer and use it in GitHub Desktop.
Save victorvoid/71558bc5921a4fcb48c6b585bfc97b73 to your computer and use it in GitHub Desktop.
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