Class: Monadic::Either::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/monadic/either.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Chain

Returns a new instance of 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