Class: Fear::Some
- Inherits:
-
Object
- Object
- Fear::Some
- Includes:
- Option
- Defined in:
- lib/fear/some.rb,
lib/fear/some/pattern_match.rb more...
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #deconstruct ⇒ Array<any>
- #empty? ⇒ false (also: #blank?)
- #filter_map(&filter) ⇒ RightBiased::Left, RightBiased::Right
- #get ⇒ any
-
#initialize(value) ⇒ Some
constructor
A new instance of Some.
- #inspect ⇒ String (also: #to_s)
- #or_nil ⇒ any
- #present? ⇒ true
- #reject ⇒ Option
- #select ⇒ Option
- #zip(other) ⇒ Fear::Option
Methods included from Option
#any?, #each, #flat_map, #get_or_else, #include?, #map, match, #match, matcher, #or_else
Constructor Details
permalink #initialize(value) ⇒ Some
Returns a new instance of Some.
12 13 14 |
# File 'lib/fear/some.rb', line 12 def initialize(value) @value = value end |
Instance Method Details
permalink #==(other) ⇒ Boolean
58 59 60 |
# File 'lib/fear/some.rb', line 58 def ==(other) other.is_a?(Some) && get == other.get end |
permalink #deconstruct ⇒ Array<any>
92 93 94 |
# File 'lib/fear/some.rb', line 92 def deconstruct [get] end |
permalink #empty? ⇒ false Also known as: blank?
27 28 29 |
# File 'lib/fear/some.rb', line 27 def empty? false end |
permalink #filter_map(&filter) ⇒ RightBiased::Left, RightBiased::Right
87 88 89 |
# File 'lib/fear/some.rb', line 87 def filter_map(&filter) map(&filter).select(&:itself) end |
permalink #get ⇒ any
17 18 19 |
# File 'lib/fear/some.rb', line 17 def get @value end |
permalink #inspect ⇒ String Also known as: to_s
63 64 65 |
# File 'lib/fear/some.rb', line 63 def inspect "#<Fear::Some get=#{value.inspect}>" end |
permalink #or_nil ⇒ any
22 23 24 |
# File 'lib/fear/some.rb', line 22 def or_nil @value end |
permalink #present? ⇒ true
34 35 36 |
# File 'lib/fear/some.rb', line 34 def present? true end |
permalink #reject ⇒ Option
48 49 50 51 52 53 54 |
# File 'lib/fear/some.rb', line 48 def reject if yield(value) None else self end end |
permalink #select ⇒ Option
39 40 41 42 43 44 45 |
# File 'lib/fear/some.rb', line 39 def select if yield(value) self else None end end |
permalink #zip(other) ⇒ Fear::Option
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fear/some.rb', line 72 def zip(other) if other.is_a?(Option) other.map do |x| if block_given? yield(value, x) else [value, x] end end else raise TypeError, "can't zip with #{other.class}" end end |