Method: Fear::Either.matcher

Defined in:
lib/fear/either.rb

.matcher {|| ... } ⇒ Fear::PartialFunction

Build pattern matcher to be used later, despite off Either#match method, id doesn’t apply matcher immanently, but build it instead. Unusually in sake of efficiency it’s better to statically build matcher and reuse it later.

Examples:

matcher =
  Either.matcher do |m|
    m.right(Integer, ->(x) { x > 2 }) { |x| x * 2 }
    m.right(String) { |x| x.to_i * 2 }
    m.left(String) { :err }
    m.else { 'error '}
  end
matcher.call(Fear.right(42))

Yield Parameters:

Returns:



314
315
316
# File 'lib/fear/either.rb', line 314

def matcher(&matcher)
  Either::PatternMatch.new(&matcher)
end