Class: Ronad::Eventually
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
- #and_then(&block) ⇒ Object
- #expand(val) ⇒ Object
-
#initialize(block) ⇒ Eventually
constructor
A new instance of Eventually.
- #monad_value ⇒ Object
Methods inherited from Monad
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( @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 (val) if Monad === val val.monad_value else val end end |
#monad_value ⇒ Object
22 23 24 |
# File 'lib/ronad/eventually.rb', line 22 def monad_value @value.call end |