Class: Mon::Monad::Reactor
Class Method Summary collapse
-
.[](fun) ⇒ Object
You want React.
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#bind(&fun) ⇒ Object
Apply fun to the value wrapped by this Reactor (which in turn is a transform on some Reactron), returning another Reactron.
- #eql?(o) ⇒ Boolean
- #equal?(o) ⇒ Boolean
-
#initialize(fun) ⇒ Reactor
constructor
A new instance of Reactor.
- #to_s ⇒ Object
-
#unwrap ⇒ Object
Unwrap the (current) value contained by this Reactor.
Methods inherited from React
Methods included from ChainableMonad
#_, #coerce, #method_missing, #respond_to?
Constructor Details
#initialize(fun) ⇒ Reactor
Returns a new instance of Reactor.
121 122 123 |
# File 'lib/monads/reactron.rb', line 121 def initialize(fun) @fun = fun 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
160 161 162 |
# File 'lib/monads/reactron.rb', line 160 def ==(o) eql? o end |
#bind(&fun) ⇒ Object
Apply fun to the value wrapped by this Reactor (which in turn is a transform on some Reactron), returning another Reactron. Changes to the root Reactron will propagate through the whole tree.
129 130 131 |
# File 'lib/monads/reactron.rb', line 129 def bind &fun Reactor[lambda { fun.call(self.unwrap) }] end |
#eql?(o) ⇒ Boolean
148 149 150 151 152 153 154 |
# File 'lib/monads/reactron.rb', line 148 def eql? o if o.is_a? React @fun.call == o.unwrap else @fun.call == o end end |
#equal?(o) ⇒ Boolean
156 157 158 |
# File 'lib/monads/reactron.rb', line 156 def equal? o eql? o end |
#to_s ⇒ Object
164 165 166 |
# File 'lib/monads/reactron.rb', line 164 def to_s "Reactor[#{ unwrap }]" end |
#unwrap ⇒ Object
Unwrap the (current) value contained by this Reactor
139 140 141 142 |
# File 'lib/monads/reactron.rb', line 139 def unwrap r = @fun.call r.is_a?(Reactor) ? r.unwrap : r end |