Class: Ronad::Eventually

Inherits:
Monad
  • Object
show all
Defined in:
lib/ronad/eventually.rb

Overview

Delayed execution. Similar to creating a closure but Eventually is compatible with the Ronad API.

Eventually is not a promise. The block in the Eventually will not execute until invoked.

Instance Method Summary collapse

Methods inherited from Monad

#continue, #value, #~@

Constructor Details

#initialize(block) ⇒ Eventually

Returns a new instance of Eventually.



8
9
10
# File 'lib/ronad/eventually.rb', line 8

def initialize block
  @value = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ronad::Monad

Instance Method Details

#and_then(&block) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/ronad/eventually.rb', line 13

def and_then &block
  new_block = lambda do
    block.call(expand @value.call)
  end

  Eventually.new new_block
end

#expand(val) ⇒ Object

Note:

can probably replace monad_value



27
28
29
30
31
32
33
# File 'lib/ronad/eventually.rb', line 27

def expand(val)
  if Monad === val
    expand val.monad_value
  else
    val
  end
end

#monad_valueObject



22
23
24
# File 'lib/ronad/eventually.rb', line 22

def monad_value
  expand @value.call
end