Class: Monadic::Either::Chain
Instance Method Summary collapse
- #bind(proc = nil, &block) ⇒ Object (also: #>=)
- #call(initial) ⇒ Object
-
#initialize(&block) ⇒ Chain
constructor
A new instance of Chain.
Constructor Details
#initialize(&block) ⇒ Chain
80 81 82 83 |
# File 'lib/monadic/either.rb', line 80 def initialize(&block) @chain = [] instance_eval(&block) end |
Instance Method Details
#bind(proc = nil, &block) ⇒ Object Also known as: >=
91 92 93 |
# File 'lib/monadic/either.rb', line 91 def bind(proc=nil, &block) @chain << (proc || block) end |
#call(initial) ⇒ Object
85 86 87 88 89 |
# File 'lib/monadic/either.rb', line 85 def call(initial) @chain.inject(Success(initial)) do |result, current| result.bind(current) end end |