Class: Fear::EitherPatternMatch Private
- Inherits:
-
PatternMatch
- Object
- PatternMatch
- Fear::EitherPatternMatch
- Defined in:
- lib/fear/either_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.
it has two optimized subclasses Fear::LeftPatternMatch
and Fear::RightPatternMatch
Either pattern matcher
@example the same matcher may be defined using block syntax
EitherPatternMatch.new 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
Direct Known Subclasses
Constant Summary collapse
- LEFT_EXTRACTOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:left_value.to_proc
- RIGHT_EXTRACTOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:right_value.to_proc
Instance Attribute Summary
Attributes inherited from PatternMatch
Instance Method Summary collapse
-
#left(*conditions, &effect) ⇒ Fear::EitherPatternMatch
(also: #failure)
private
Match against
Fear::Left
. -
#right(*conditions, &effect) ⇒ Fear::EitherPatternMatch
(also: #success)
private
Match against
Fear::Right
.
Methods inherited from PatternMatch
__new__, #case, #else, #initialize, mixin, new, #or_else, #xcase
Constructor Details
This class inherits a constructor from Fear::PatternMatch
Instance Method Details
#left(*conditions, &effect) ⇒ Fear::EitherPatternMatch Also known as: failure
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::Left
42 43 44 45 |
# File 'lib/fear/either_pattern_match.rb', line 42 def left(*conditions, &effect) branch = Fear.case(Fear::Left, &LEFT_EXTRACTOR).and_then(Fear.case(*conditions, &effect)) or_else(branch) end |
#right(*conditions, &effect) ⇒ Fear::EitherPatternMatch Also known as: success
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::Right
32 33 34 35 |
# File 'lib/fear/either_pattern_match.rb', line 32 def right(*conditions, &effect) branch = Fear.case(Fear::Right, &RIGHT_EXTRACTOR).and_then(Fear.case(*conditions, &effect)) or_else(branch) end |