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