Module: Fr::Reader

Extended by:
Monad
Defined in:
lib/fr/monad/reader.rb

Class Method Summary collapse

Methods included from Monad

applyM, composeM, filterM, foldM, forM, join, liftM, mapM, sequence, unlessM, whenM, zipM

Methods included from Functor

#void

Class Method Details

.askObject

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

.unit(value) ⇒ Object

Combinators



22
23
24
25
26
# File 'lib/fr/monad/reader.rb', line 22

def unit(value)
  lambda do |state|
    Hash[state: state, value: value]
  end
end