Class: Monadt::DoMEnumerator

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

Class Method Summary collapse

Class Method Details

.do_m(klass, &blk) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/monadt/do_m/enumerator.rb', line 23

def do_m(klass, &blk)
  e = Enumerator.new do |y|
    m_obj = Enum::MonadObj.new klass, y
    blk.call(m_obj)
  end
  do_m_recur(klass, e)
end

.do_m_recur(klass, e) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/monadt/do_m/enumerator.rb', line 31

def do_m_recur(klass, e)
  begin
    ma = e.next
  rescue StopIteration => ex
    return ex.result
  end
  klass.bind(ma) do |a|
    e.feed a
    do_m_recur(klass, e)
  end
end