Class: Fear::Try::PatternMatch 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::Success::PatternMatch 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::Try::PatternMatch

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:



23
24
25
26
# File 'lib/fear/try/pattern_match.rb', line 23

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

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

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:



14
15
16
17
# File 'lib/fear/try/pattern_match.rb', line 14

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