Class: Mon::Monad::React

Inherits:
Monad
  • Object
show all
Includes:
ChainableMonad
Defined in:
lib/monads/reactron.rb

Overview

The React class is the parent of Reactron and Reactor. The key difference between the two is the presence of the << operator. The value of a Reactor is derived from a Reactron, and cannot be directly changed. If viewed as a tree, Reactrons are the root, and only the root may be changed.

However, we can have more than one root! m = React[2] # ==> Reactron[2] n = React[10] # ==> Reactron[10] v = m * n # Currently v == Reactor[20] n << 5 # Now v == Reactor[10]

Usage of React is straightforward: r = React[some_value]

Direct Known Subclasses

Reactor, Reactron

Class Method Summary collapse

Methods included from ChainableMonad

#_, #coerce, #method_missing, #respond_to?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mon::Monad::ChainableMonad

Class Method Details

.[](obj) ⇒ Object

Wrap a value in a Reactron: <tt>r = React # ==> Reactron



40
41
42
43
44
45
46
# File 'lib/monads/reactron.rb', line 40

def self::[] obj
  if (obj.is_a? Proc)
    Reactor[obj]
  else
    Reactron[obj]
  end
end

.valid?(v) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/monads/reactron.rb', line 52

def self::valid?(v)
  v.is_a? React
end