Class: Fear::Success
- Inherits:
-
Object
show all
- Includes:
- Try
- Defined in:
- lib/fear/success.rb,
lib/fear/success/pattern_match.rb
Instance Method Summary
collapse
Methods included from Try
#any?, #each, #get_or_else, #include?, #match, matcher, #to_option
Constructor Details
#initialize(value) ⇒ Success
Returns a new instance of Success.
13
14
15
|
# File 'lib/fear/success.rb', line 13
def initialize(value)
@value = value
end
|
Instance Method Details
#==(other) ⇒ Boolean
90
91
92
|
# File 'lib/fear/success.rb', line 90
def ==(other)
other.is_a?(Success) && value == other.value
end
|
#deconstruct ⇒ <any>
103
104
105
|
# File 'lib/fear/success.rb', line 103
def deconstruct
[value]
end
|
#failure? ⇒ false
28
29
30
|
# File 'lib/fear/success.rb', line 28
def failure?
false
end
|
#flat_map ⇒ Try
77
78
79
80
81
|
# File 'lib/fear/success.rb', line 77
def flat_map
super
rescue StandardError => error
Failure.new(error)
end
|
#flatten ⇒ Try
38
39
40
41
42
43
44
|
# File 'lib/fear/success.rb', line 38
def flatten
if value.is_a?(Try)
value.flatten
else
self
end
end
|
#get ⇒ any
18
19
20
|
# File 'lib/fear/success.rb', line 18
def get
@value
end
|
#inspect ⇒ String
Also known as:
to_s
95
96
97
|
# File 'lib/fear/success.rb', line 95
def inspect
"#<Fear::Success value=#{value.inspect}>"
end
|
#map ⇒ Try
70
71
72
73
74
|
# File 'lib/fear/success.rb', line 70
def map
super
rescue StandardError => error
Failure.new(error)
end
|
33
34
35
|
# File 'lib/fear/success.rb', line 33
def or_else
self
end
|
65
66
67
|
# File 'lib/fear/success.rb', line 65
def recover
self
end
|
#recover_with ⇒ Success
60
61
62
|
# File 'lib/fear/success.rb', line 60
def recover_with
self
end
|
#select {|value| ... } ⇒ Try
49
50
51
52
53
54
55
56
57
|
# File 'lib/fear/success.rb', line 49
def select
if yield(value)
self
else
raise NoSuchElementError, "Predicate does not hold for `#{value}`"
end
rescue StandardError => error
Failure.new(error)
end
|
#success? ⇒ Boolean
23
24
25
|
# File 'lib/fear/success.rb', line 23
def success?
true
end
|
#to_either ⇒ Right
84
85
86
|
# File 'lib/fear/success.rb', line 84
def to_either
Right.new(value)
end
|