Module: Fr::Reader
- Extended by:
- Monad
- Defined in:
- lib/fr/monad/reader.rb
Class Method Summary collapse
-
.ask ⇒ Object
Actions.
- .bind(f, &g) ⇒ Object
- .eval(computation, state) ⇒ Object
-
.run(computation, state) ⇒ Object
Evaluators.
-
.unit(value) ⇒ Object
Combinators.
Methods included from Monad
applyM, composeM, filterM, foldM, forM, join, liftM, mapM, sequence, unlessM, whenM, zipM
Methods included from Functor
Class Method Details
.ask ⇒ Object
Actions
39 40 41 42 43 |
# File 'lib/fr/monad/reader.rb', line 39 def ask lambda do |state| Hash[state: state, value: state] end end |
.bind(f, &g) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/fr/monad/reader.rb', line 28 def bind(f, &g) lambda do |state| tuple = f.call(state) g.call(tuple[:value]) .call(tuple[:state]) end end |
.eval(computation, state) ⇒ Object
15 16 17 |
# File 'lib/fr/monad/reader.rb', line 15 def eval(computation, state) computation.call(state)[:value] end |
.run(computation, state) ⇒ Object
Evaluators
11 12 13 |
# File 'lib/fr/monad/reader.rb', line 11 def run(computation, state) computation.call(state) end |