Class: Mon::Monad::Final
- Inherits:
-
Lazy
- Object
- Mon::Monad
- Lazy
- Mon::Monad::Final
- Defined in:
- lib/monads/lazy.rb
Overview
Final represents a finalized lazy value (i.e. a value with no pending ops).
Class Method Summary collapse
-
.[](obj = nil) ⇒ Object
You probably want Lazy.
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#_ ⇒ Object
Alias for #unwrap.
- #_canBind?(name) ⇒ Boolean
- #_finalized? ⇒ Boolean
-
#bind(&fun) ⇒ Object
Add an operation to be performed on the wrapped value, only if necessary.
- #eql?(o) ⇒ Boolean
- #equals?(o) ⇒ Boolean
-
#finalize ⇒ Object
Perform any pending lazy operations.
-
#initialize(obj) ⇒ Final
constructor
A new instance of Final.
- #to_s ⇒ Object
-
#unwrap ⇒ Object
Perform any pending lazy operations and unwrap the result.
Methods inherited from Lazy
Methods included from ChainableMonad
#coerce, #method_missing, #respond_to?
Constructor Details
#initialize(obj) ⇒ Final
Returns a new instance of Final.
66 67 68 |
# File 'lib/monads/lazy.rb', line 66 def initialize(obj) @obj = obj end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mon::Monad::ChainableMonad
Class Method Details
Instance Method Details
#==(o) ⇒ Object
120 121 122 |
# File 'lib/monads/lazy.rb', line 120 def == o eql? o end |
#_ ⇒ Object
Alias for #unwrap
99 100 101 |
# File 'lib/monads/lazy.rb', line 99 def _ unwrap end |
#_canBind?(name) ⇒ Boolean
85 86 87 |
# File 'lib/monads/lazy.rb', line 85 def _canBind?(name) @obj.respond_to? name end |
#_finalized? ⇒ Boolean
89 90 91 |
# File 'lib/monads/lazy.rb', line 89 def _finalized? true end |
#bind(&fun) ⇒ Object
Add an operation to be performed on the wrapped value, only if necessary
76 77 78 |
# File 'lib/monads/lazy.rb', line 76 def bind(&fun) Pending::eventually(fun, [@obj]) end |
#eql?(o) ⇒ Boolean
107 108 109 110 111 112 113 114 |
# File 'lib/monads/lazy.rb', line 107 def eql? o # Time to collapse if o.is_a? Lazy self.unwrap == o.unwrap else self.unwrap == o end end |
#equals?(o) ⇒ Boolean
116 117 118 |
# File 'lib/monads/lazy.rb', line 116 def equals? o eql? o end |
#finalize ⇒ Object
Perform any pending lazy operations
81 82 83 |
# File 'lib/monads/lazy.rb', line 81 def finalize self end |
#to_s ⇒ Object
103 104 105 |
# File 'lib/monads/lazy.rb', line 103 def to_s "Final[#{ @obj }]" end |
#unwrap ⇒ Object
Perform any pending lazy operations and unwrap the result
94 95 96 |
# File 'lib/monads/lazy.rb', line 94 def unwrap @obj end |