class Mon::Monad::Reactron

The Reactron class represents a changeable value, from which other values can be derived (as Reactrons)

Public Class Methods

[](obj) click to toggle source

You should be using React

# File lib/monads/reactron.rb, line 66
def self::[] obj
  Reactron.new(obj)
end

Protected Class Methods

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

Public Instance Methods

<<(obj) click to toggle source

Change the value of this Reactron

# File lib/monads/reactron.rb, line 87
def << obj
  @obj = obj
  self
end
==(o) click to toggle source
# File lib/monads/reactron.rb, line 104
def ==(o)
  eql? o
end
bind(&fun) click to toggle source

Apply fun to the value wrapped by this Reactron. Returns a Reactor. Whenever the value is changed (with <<), all derived Reactors are also updated.

# File lib/monads/reactron.rb, line 73
def bind &fun
  Reactor[lambda { fun.call(self.unwrap) }]
end
eql?(o) click to toggle source
# File lib/monads/reactron.rb, line 92
def eql? o
  if o.is_a? React
    @obj == o.unwrap
  else
    @obj == o
  end
end
equal?(o) click to toggle source
# File lib/monads/reactron.rb, line 100
def equal? o
  eql? o
end
to_s() click to toggle source
# File lib/monads/reactron.rb, line 108
def to_s
  "Reactron[#{ @obj }]"
end
unwrap() click to toggle source

Unwrap the value contained by this Reactron

# File lib/monads/reactron.rb, line 82
def unwrap
  @obj
end

Protected Instance Methods

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