Skip to content

Instantly share code, notes, and snippets.

@DrBoolean
Created July 20, 2017 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrBoolean/daef39ce371d669e2f9f4b4bbefb0d8d to your computer and use it in GitHub Desktop.
Save DrBoolean/daef39ce371d669e2f9f4b4bbefb0d8d to your computer and use it in GitHub Desktop.
rep9
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