Method: Monadic::Either#bind

Defined in:
lib/monadic/either.rb

#bind(proc = nil, &block) ⇒ Success, Failure Also known as: >=, +

Allows privileged access to the Either‘s inner value from within a block. This block should return a Success or Failure itself. It will be coerced into #Either

Returns:



24
25
26
27
28
29
30
31
32
33
# File 'lib/monadic/either.rb', line 24

def bind(proc=nil, &block)
  return self if failure?
  return concat(proc) if proc.is_a? Either

  begin
    Either(call(proc, block))
  rescue StandardError => error
    Failure(error)
  end
end