Class: Fear::Either::PatternMatch Private
- Inherits:
-
PatternMatch
- Object
- PatternMatch
- Fear::Either::PatternMatch
- 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.
Note:
it has two optimized subclasses Fear::Left::PatternMatch
and Fear::Right::PatternMatch
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
Instance Attribute Summary
Attributes inherited from PatternMatch
Instance Method Summary collapse
-
#left(*conditions, &effect) ⇒ Fear::Either::PatternMatch
(also: #failure)
private
Match against
Fear::Left
. -
#right(*conditions, &effect) ⇒ Fear::Either::PatternMatch
(also: #success)
private
Match against
Fear::Right
.
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
#left(*conditions, &effect) ⇒ Fear::Either::PatternMatch 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_value).and_then(Fear.case(*conditions, &effect)) or_else(branch) end |
#right(*conditions, &effect) ⇒ Fear::Either::PatternMatch 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_value).and_then(Fear.case(*conditions, &effect)) or_else(branch) end |