Class: Fear::PartialFunction::Guard Private
- Inherits:
-
Object
- Object
- Fear::PartialFunction::Guard
- Defined in:
- lib/fear/partial_function/guard.rb,
lib/fear/partial_function/guard/or.rb,
lib/fear/partial_function/guard/and.rb,
lib/fear/partial_function/guard/and3.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.
Guard represents PartialFunction guardian
Defined Under Namespace
Class Method Summary collapse
- .and(conditions) ⇒ Fear::PartialFunction::Guard private
- .and1(c) ⇒ Object private
-
.and2(c1, c2) ⇒ Object
private
Optimized version for combination of two guardians Two guarding is a very common situation.
- .and3(c1, c2, c3) ⇒ Object private
- .or(conditions) ⇒ Fear::PartialFunction::Guard private
Instance Method Summary collapse
- #===(arg) ⇒ Boolean private
- #and(other) ⇒ Fear::PartialFunction::Guard private
-
#initialize(condition) ⇒ Guard
constructor
private
A new instance of Guard.
- #or(other) ⇒ Fear::PartialFunction::Guard private
Constructor Details
#initialize(condition) ⇒ Guard
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.
Returns a new instance of Guard.
51 52 53 |
# File 'lib/fear/partial_function/guard.rb', line 51 def initialize(condition) @condition = condition end |
Class Method Details
.and(conditions) ⇒ Fear::PartialFunction::Guard
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.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fear/partial_function/guard.rb', line 28 def and(conditions) case conditions.size when 1 then and1(*conditions) when 2 then and2(*conditions) when 3 then and3(*conditions) when 0 then Any else head, *tail = conditions tail.reduce(new(head)) { |acc, condition| acc.and(new(condition)) } end end |
.and1(c) ⇒ Object
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.
22 23 24 |
# File 'lib/fear/partial_function/guard.rb', line 22 def and1(c) c end |
.and2(c1, c2) ⇒ Object
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.
Optimized version for combination of two guardians Two guarding is a very common situation. For example checking for Some, and checking a value withing container.
14 15 16 |
# File 'lib/fear/partial_function/guard.rb', line 14 def and2(c1, c2) Guard::And.new(c1, c2) end |
.and3(c1, c2, c3) ⇒ Object
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.
18 19 20 |
# File 'lib/fear/partial_function/guard.rb', line 18 def and3(c1, c2, c3) Guard::And3.new(c1, c2, c3) end |
.or(conditions) ⇒ Fear::PartialFunction::Guard
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.
42 43 44 45 46 47 |
# File 'lib/fear/partial_function/guard.rb', line 42 def or(conditions) return Any if conditions.empty? head, *tail = conditions tail.reduce(new(head)) { |acc, condition| acc.or(new(condition)) } end |
Instance Method Details
#===(arg) ⇒ Boolean
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.
71 72 73 |
# File 'lib/fear/partial_function/guard.rb', line 71 def ===(arg) condition === arg end |
#and(other) ⇒ Fear::PartialFunction::Guard
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.
59 60 61 |
# File 'lib/fear/partial_function/guard.rb', line 59 def and(other) Guard::And.new(condition, other) end |
#or(other) ⇒ Fear::PartialFunction::Guard
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.
65 66 67 |
# File 'lib/fear/partial_function/guard.rb', line 65 def or(other) Guard::Or.new(condition, other) end |