Created
July 5, 2016 18:42
-
-
Save evilsoft/2e5afd5232f6e62488f88203b0d228a9 to your computer and use it in GitHub Desktop.
Just an IO with map and chain
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
import compose from 'ramda/src/compose' | |
import curry from 'ramda/src/curry' | |
import map from 'ramda/src/map' | |
import always from 'ramda/src/always' | |
const chain = curry((fn, m) => m.chain(fn)) | |
function IO(run) { | |
const map = fn => IO(compose(fn, run)) | |
const chain = fn => IO(() => map(fn).run().run()) | |
return { run, map, chain } | |
} | |
const valIO = x => IO(() => x) | |
const logIO = x => IO(() => compose(always(x), console.log.bind(console, 'from logIO'))(x)) | |
const flow = compose(chain(logIO), map(x => x + 5), chain(logIO), valIO) | |
console.log(flow(3).run()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment