Class: Monadt::AsyncEither

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

Class Method Summary collapse

Methods included from Adt

match, with

Class Method Details

.bind(m, &blk) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/monadt/async_either.rb', line 9

def bind(m, &blk)
  a = m.resume
  match(a,
    with(Either::Left) { |v| Async.return a },
    with(Either::Right) { |v|
      m2 = blk.call(v)
      if m2.alive?
        m2
      else
        Async.return a
      end
    })
end

.return(a) ⇒ Object



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

def return(a)
  Async.return(Either.return(a))
end