-
-
Save victorvoid/71558bc5921a4fcb48c6b585bfc97b73 to your computer and use it in GitHub Desktop.
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 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