Class: Fear::TryPatternMatch Private

Inherits:
PatternMatch show all
Defined in:
lib/fear/try_pattern_match.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

it has two optimized subclasses Fear::SuccessPatternMatch and Fear::FailurePatternMatch

Try pattern matcher

Instance Attribute Summary

Attributes inherited from PatternMatch

#result

Instance Method Summary collapse

Methods inherited from PatternMatch

__new__, #case, #else, #initialize, mixin, new, #or_else

Constructor Details

This class inherits a constructor from Fear::PatternMatch

Instance Method Details

#failure(*conditions, &effect) ⇒ Fear::TryPatternMatch

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Match against Fear::Failure

Parameters:

  • conditions (<#==>)

Returns:



24
25
26
27
# File 'lib/fear/try_pattern_match.rb', line 24

def failure(*conditions, &effect)
  branch = Fear.case(Fear::Failure, &:exception).and_then(Fear.case(*conditions, &effect))
  or_else(branch)
end

#success(*conditions, &effect) ⇒ Fear::TryPatternMatch

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Match against Fear::Success

Parameters:

  • conditions (<#==>)

Returns:



15
16
17
18
# File 'lib/fear/try_pattern_match.rb', line 15

def success(*conditions, &effect)
  branch = Fear.case(Fear::Success, &:get).and_then(Fear.case(*conditions, &effect))
  or_else(branch)
end