Class: Fear::Success
Constant Summary
collapse
proc do |try|
if Fear::Success === try
Fear.some([try.get])
else
Fear.none
end
end
Instance Method Summary
collapse
#===, #any?, #each, #get_or_else, #include?, included, #to_option
Methods included from Try
#any?, #each, #get_or_else, #include?, #left_class, #match, matcher, #right_class, #to_option
Constructor Details
#initialize(value) ⇒ Success
Returns a new instance of Success.
21
22
23
|
# File 'lib/fear/success.rb', line 21
def initialize(value)
@value = value
end
|
Instance Method Details
#==(other) ⇒ Boolean
98
99
100
|
# File 'lib/fear/success.rb', line 98
def ==(other)
other.is_a?(Success) && value == other.value
end
|
#failure? ⇒ false
36
37
38
|
# File 'lib/fear/success.rb', line 36
def failure?
false
end
|
#flat_map ⇒ Try
85
86
87
88
89
|
# File 'lib/fear/success.rb', line 85
def flat_map
super
rescue StandardError => error
Failure.new(error)
end
|
#flatten ⇒ Try
46
47
48
49
50
51
52
|
# File 'lib/fear/success.rb', line 46
def flatten
if value.is_a?(Try)
value.flatten
else
self
end
end
|
#get ⇒ any
26
27
28
|
# File 'lib/fear/success.rb', line 26
def get
@value
end
|
#inspect ⇒ String
Also known as:
to_s
103
104
105
|
# File 'lib/fear/success.rb', line 103
def inspect
"#<Fear::Success value=#{value.inspect}>"
end
|
#map ⇒ Try
78
79
80
81
82
|
# File 'lib/fear/success.rb', line 78
def map
super
rescue StandardError => error
Failure.new(error)
end
|
41
42
43
|
# File 'lib/fear/success.rb', line 41
def or_else
self
end
|
73
74
75
|
# File 'lib/fear/success.rb', line 73
def recover
self
end
|
#recover_with ⇒ Success
68
69
70
|
# File 'lib/fear/success.rb', line 68
def recover_with
self
end
|
#select {|value| ... } ⇒ Try
57
58
59
60
61
62
63
64
65
|
# File 'lib/fear/success.rb', line 57
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
31
32
33
|
# File 'lib/fear/success.rb', line 31
def success?
true
end
|
#to_either ⇒ Right
92
93
94
|
# File 'lib/fear/success.rb', line 92
def to_either
Right.new(value)
end
|