Class: Fear::Some
- Inherits:
-
Object
show all
- Includes:
- Option
- Defined in:
- lib/fear/some.rb,
lib/fear/some/pattern_match.rb
Instance Method Summary
collapse
Methods included from Option
#any?, #each, #flat_map, #get_or_else, #include?, #map, match, #match, matcher, #or_else
Constructor Details
#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
#==(other) ⇒ Boolean
58
59
60
|
# File 'lib/fear/some.rb', line 58
def ==(other)
other.is_a?(Some) && get == other.get
end
|
#deconstruct ⇒ Array<any>
92
93
94
|
# File 'lib/fear/some.rb', line 92
def deconstruct
[get]
end
|
#empty? ⇒ false
Also known as:
blank?
27
28
29
|
# File 'lib/fear/some.rb', line 27
def empty?
false
end
|
#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
|
#get ⇒ any
17
18
19
|
# File 'lib/fear/some.rb', line 17
def get
@value
end
|
#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
|
#or_nil ⇒ any
22
23
24
|
# File 'lib/fear/some.rb', line 22
def or_nil
@value
end
|
#present? ⇒ true
34
35
36
|
# File 'lib/fear/some.rb', line 34
def present?
true
end
|
48
49
50
51
52
53
54
|
# File 'lib/fear/some.rb', line 48
def reject
if yield(value)
None
else
self
end
end
|
39
40
41
42
43
44
45
|
# File 'lib/fear/some.rb', line 39
def select
if yield(value)
self
else
None
end
end
|
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
|