Class: Fear::Right
- Inherits:
-
Object
show all
- Includes:
- Either
- Defined in:
- lib/fear/right.rb
Constant Summary
collapse
proc do |either|
if Fear::Right === either
Fear.some([either.right_value])
else
Fear.none
end
end
Instance Method Summary
collapse
Methods included from Either
#==, #any?, #deconstruct, #each, #flat_map, #get_or_else, #include?, #initialize, #inspect, #map, #match, matcher, #or_else, #to_option
Instance Method Details
#join_left ⇒ self
84
85
86
|
# File 'lib/fear/right.rb', line 84
def join_left
self
end
|
#join_right ⇒ Either
77
78
79
80
81
|
# File 'lib/fear/right.rb', line 77
def join_right
value.tap do |v|
Utils.assert_type!(v, Either)
end
end
|
#left? ⇒ false
Also known as:
failure?
31
32
33
|
# File 'lib/fear/right.rb', line 31
def left?
false
end
|
#reduce(_reduce_left, reduce_right) ⇒ any
71
72
73
|
# File 'lib/fear/right.rb', line 71
def reduce(_reduce_left, reduce_right)
reduce_right.(value)
end
|
56
57
58
59
60
61
62
|
# File 'lib/fear/right.rb', line 56
def reject
if yield(value)
Left.new(value)
else
self
end
end
|
#right? ⇒ true
Also known as:
success?
25
26
27
|
# File 'lib/fear/right.rb', line 25
def right?
true
end
|
#right_value ⇒ 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.
20
21
22
|
# File 'lib/fear/right.rb', line 20
def right_value
value
end
|
47
48
49
50
51
52
53
|
# File 'lib/fear/right.rb', line 47
def select
if yield(value)
self
else
Left.new(value)
end
end
|
#select_or_else(default) ⇒ Either
38
39
40
41
42
43
44
|
# File 'lib/fear/right.rb', line 38
def select_or_else(default)
if yield(value)
self
else
Left.new(Utils.return_or_call_proc(default))
end
end
|
65
66
67
|
# File 'lib/fear/right.rb', line 65
def swap
Left.new(value)
end
|