Skip to content

Instantly share code, notes, and snippets.

@evilsoft
Created July 5, 2016 18:42
Show Gist options
  • Save evilsoft/2e5afd5232f6e62488f88203b0d228a9 to your computer and use it in GitHub Desktop.
Save evilsoft/2e5afd5232f6e62488f88203b0d228a9 to your computer and use it in GitHub Desktop.
Just an IO with map and chain
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