class Fear::OptionPatternMatch

Option pattern matcher

@example

 pattern_match =
   OptionPatternMatch.new
     .some(Integer) { |x| x * 2 }
     .some(String) { |x| x.to_i * 2 }
     .none { 'NaN' }
     .else { 'error '}

 pattern_match.call(42) => 'NaN'

@example the same matcher may be defined using block syntax
  OptionPatternMatch.new do |m|
     m.some(Integer) { |x| x * 2 }
     m.some(String) { |x| x.to_i * 2 }
     m.none { 'NaN' }
     m.else { 'error '}
  end

@note it has two optimized subclasses Fear::SomePatternMatch and Fear::NonePatternMatch @api private

Constants

GET_METHOD

Public Instance Methods

none(&effect) click to toggle source

Match against None

@param effect [Proc] @return [Fear::OptionPatternMatch]

# File lib/fear/option_pattern_match.rb, line 43
def none(&effect)
  branch = Fear.case(Fear::None, &effect)
  or_else(branch)
end
some(*conditions, &effect) click to toggle source

Match against Some

@param conditions [<#==>] @return [Fear::OptionPatternMatch]

# File lib/fear/option_pattern_match.rb, line 34
def some(*conditions, &effect)
  branch = Fear.case(Fear::Some, &GET_METHOD).and_then(Fear.case(*conditions, &effect))
  or_else(branch)
end