Class: Either::Chain
- Inherits:
-
Object
- Object
- Either::Chain
- Defined in:
- lib/monadic/either.rb
Instance Method Summary collapse
- #bind(proc = nil, &block) ⇒ Object (also: #chain)
- #call(initial) ⇒ Object
-
#initialize(&block) ⇒ Chain
constructor
A new instance of Chain.
Constructor Details
#initialize(&block) ⇒ Chain
Returns a new instance of Chain.
54 55 56 57 |
# File 'lib/monadic/either.rb', line 54 def initialize(&block) @chain = [] instance_eval(&block) end |
Instance Method Details
#bind(proc = nil, &block) ⇒ Object Also known as: chain
65 66 67 |
# File 'lib/monadic/either.rb', line 65 def bind(proc=nil, &block) @chain << (proc || block) end |
#call(initial) ⇒ Object
59 60 61 62 63 |
# File 'lib/monadic/either.rb', line 59 def call(initial) @chain.inject(Success(initial)) do |result, current| result.bind(current) end end |