Class: Monadt::Monad

Inherits:
Object
  • Object
show all
Defined in:
lib/monadt.rb,
lib/monadt/do_m.rb

Class Method Summary collapse

Class Method Details

.async(&blk) ⇒ Object



24
25
26
# File 'lib/monadt.rb', line 24

def async(&blk)
  do_m(Async, &blk)
end

.async_either(&blk) ⇒ Object



28
29
30
# File 'lib/monadt.rb', line 28

def async_either(&blk)
  do_m(AsyncEither, &blk)
end

.do_m(klass, &blk) ⇒ Object



16
17
18
# File 'lib/monadt/do_m.rb', line 16

def do_m(klass, &blk)
  engine.do_m(klass, &blk)
end

.either(&blk) ⇒ Object



20
21
22
# File 'lib/monadt.rb', line 20

def either(&blk)
  do_m(Either, &blk)
end

.engineObject



8
9
10
11
12
13
14
# File 'lib/monadt/do_m.rb', line 8

def engine
  if ENV['DO_M_ENGINE'].nil?
    DoMFiber
  else
    Object.const_get(ENV['DO_M_ENGINE'])
  end
end

.maybe(&blk) ⇒ Object



12
13
14
# File 'lib/monadt.rb', line 12

def maybe(&blk)
  do_m(Maybe, &blk)
end

.present(&blk) ⇒ Object



16
17
18
# File 'lib/monadt.rb', line 16

def present(&blk)
  do_m(Present, &blk)
end

.reader(&blk) ⇒ Object



41
42
43
# File 'lib/monadt.rb', line 41

def reader(&blk)
  do_m(Reader, &blk)
end

.reader_state_choice(&blk) ⇒ Object



49
50
51
# File 'lib/monadt.rb', line 49

def reader_state_choice(&blk)
  do_m(ReaderStateEither, &blk)
end

.run_reader(env, &blk) ⇒ Object



45
46
47
# File 'lib/monadt.rb', line 45

def run_reader(env, &blk)
  reader(&blk).(env)
end

.run_reader_state_choice(env, initial_state, &blk) ⇒ Object



53
54
55
# File 'lib/monadt.rb', line 53

def run_reader_state_choice(env, initial_state, &blk)
  reader_state_choice(&blk).(env, initial_state).first
end

.run_state(initial_state, &blk) ⇒ Object



36
37
38
39
# File 'lib/monadt.rb', line 36

def run_state(initial_state, &blk)
  prc = state(&blk)
  prc.(initial_state).first
end

.state(&blk) ⇒ Object



32
33
34
# File 'lib/monadt.rb', line 32

def state(&blk)
  do_m(State, &blk)
end