Module: Fr::Writer
- Extended by:
- Monad
- Defined in:
- lib/fr/monad/writer.rb
Class Method Summary collapse
- .bind(f, &g) ⇒ Object
- .eval(computation, monoid) ⇒ Object
- .exec(computation, monoid) ⇒ Object
-
.run(computation, monoid) ⇒ Object
Evaluators.
-
.tell(write) ⇒ Object
Actions.
-
.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
.bind(f, &g) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/fr/monad/writer.rb', line 32 def bind(f, &g) lambda do |state, monoid| tuple = f.call(state, monoid) g.call(tuple[:value]) .call(tuple[:state], tuple[:monoid]) end end |
.eval(computation, monoid) ⇒ Object
15 16 17 |
# File 'lib/fr/monad/writer.rb', line 15 def eval(computation, monoid) computation.call(monoid.zero, monoid)[:value] end |
.exec(computation, monoid) ⇒ Object
19 20 21 |
# File 'lib/fr/monad/writer.rb', line 19 def exec(computation, monoid) computation.call(monoid.zero, monoid)[:state] end |
.run(computation, monoid) ⇒ Object
Evaluators
11 12 13 |
# File 'lib/fr/monad/writer.rb', line 11 def run(computation, monoid) computation.call(monoid.zero, monoid) end |