Class: Fear::Some
- Inherits:
-
Object
show all
- Includes:
- Option
- Defined in:
- lib/fear/some.rb
Constant Summary
collapse
proc do |option|
if Fear::Some === option
Fear.some([option.get])
else
Fear.none
end
end
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.
22
23
24
|
# File 'lib/fear/some.rb', line 22
def initialize(value)
@value = value
end
|
Instance Method Details
#==(other) ⇒ Boolean
61
62
63
|
# File 'lib/fear/some.rb', line 61
def ==(other)
other.is_a?(Some) && get == other.get
end
|
#deconstruct ⇒ Array<any>
95
96
97
|
# File 'lib/fear/some.rb', line 95
def deconstruct
[get]
end
|
#empty? ⇒ false
37
38
39
|
# File 'lib/fear/some.rb', line 37
def empty?
false
end
|
#filter_map(&filter) ⇒ RightBiased::Left, RightBiased::Right
90
91
92
|
# File 'lib/fear/some.rb', line 90
def filter_map(&filter)
map(&filter).select(&:itself)
end
|
#get ⇒ any
27
28
29
|
# File 'lib/fear/some.rb', line 27
def get
@value
end
|
#inspect ⇒ String
Also known as:
to_s
66
67
68
|
# File 'lib/fear/some.rb', line 66
def inspect
"#<Fear::Some get=#{value.inspect}>"
end
|
#or_nil ⇒ any
32
33
34
|
# File 'lib/fear/some.rb', line 32
def or_nil
@value
end
|
51
52
53
54
55
56
57
|
# File 'lib/fear/some.rb', line 51
def reject
if yield(value)
None
else
self
end
end
|
42
43
44
45
46
47
48
|
# File 'lib/fear/some.rb', line 42
def select
if yield(value)
self
else
None
end
end
|
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/fear/some.rb', line 75
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
|