Class: Monadt::ReaderStateEitherM

Inherits:
Object
  • Object
show all
Extended by:
Adt
Defined in:
lib/monadt/reader_state_either.rb

Class Method Summary collapse

Methods included from Adt

match, with

Class Method Details

.bind(m, &blk) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/monadt/reader_state_either.rb', line 8

def bind(m, &blk)
  ->(e, s) {
    c, s2 = m.(e, s)
    match(c,
      with(Either::Left) {|v| [c, s2]},
      with(Either::Right) {|v|
        blk.call(v).(e, s2)
      })
  }
end

.return(val) ⇒ Object



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

def return(val)
  ->(e, s) { [EitherM.return(val), s] }
end