class Mon::Monad::Reactor

Public Class Methods

[](fun) click to toggle source

You want React

# File lib/monads/reactron.rb, line 134
def self::[] fun
  Reactor.new(fun)
end

Protected Class Methods

new(fun) click to toggle source
# File lib/monads/reactron.rb, line 121
def initialize(fun)
  @fun = fun
end

Public Instance Methods

==(o) click to toggle source
# File lib/monads/reactron.rb, line 160
def ==(o)
  eql? o
end
bind(&fun) click to toggle source

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.

# File lib/monads/reactron.rb, line 129
def bind &fun
  Reactor[lambda { fun.call(self.unwrap) }]
end
eql?(o) click to toggle source
# 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) click to toggle source
# File lib/monads/reactron.rb, line 156
def equal? o
  eql? o
end
to_s() click to toggle source
# File lib/monads/reactron.rb, line 164
def to_s
  "Reactor[#{ unwrap }]"
end
unwrap() click to toggle source

Unwrap the (current) value contained by this Reactor

# File lib/monads/reactron.rb, line 139
def unwrap
  r = @fun.call
  r.is_a?(Reactor) ? r.unwrap : r
end

Protected Instance Methods

_canBind?(name) click to toggle source
# File lib/monads/reactron.rb, line 144
def _canBind? name
  unwrap.respond_to? name
end