Created
July 20, 2017 20:32
-
-
Save DrBoolean/daef39ce371d669e2f9f4b4bbefb0d8d to your computer and use it in GitHub Desktop.
rep9
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 Reader = f => | |
({ | |
run: f, | |
map: g => Reader(x => g(f(x))), | |
chain: g => Reader(x => g(f(x)).run(x)) | |
}) | |
Reader.of = x => Reader(() => x) | |
// function application | |
Reader(x => x + 1).run(2) // 3 | |
// map is just function composition | |
Reader(x => ‘hello ${x}’) | |
.map(x => x.toUpperCase()) | |
.run(‘world’) // HELLO WORLD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment