Created
August 20, 2018 07:24
-
-
Save leihuang23/272bc283762c11885a0982a6d61ac1dc to your computer and use it in GitHub Desktop.
The IO monad implemented with JavaScript factory function
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
function IO(effectFn) { | |
const __val = effectFn; | |
const map = fn => IO(() => fn(__val())); | |
const performUnsafeIO = () => __val(); | |
const chain = fn => IO(() => fn(__val()).performUnsafeIO()); | |
return Object.freeze({ | |
map, | |
chain, | |
performUnsafeIO | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment