Class: Fear::Success
- Inherits:
-
Object
show all
- Includes:
- Try
- Defined in:
- lib/fear/success.rb
Constant Summary
collapse
proc do |try|
if Fear::Success === try
Fear.some([try.get])
else
Fear.none
end
end
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.
19
20
21
|
# File 'lib/fear/success.rb', line 19
def initialize(value)
@value = value
end
|
Instance Method Details
#==(other) ⇒ Boolean
96
97
98
|
# File 'lib/fear/success.rb', line 96
def ==(other)
other.is_a?(Success) && value == other.value
end
|
#failure? ⇒ false
34
35
36
|
# File 'lib/fear/success.rb', line 34
def failure?
false
end
|
#flat_map ⇒ Try
83
84
85
86
87
|
# File 'lib/fear/success.rb', line 83
def flat_map
super
rescue StandardError => error
Failure.new(error)
end
|
#flatten ⇒ Try
44
45
46
47
48
49
50
|
# File 'lib/fear/success.rb', line 44
def flatten
if value.is_a?(Try)
value.flatten
else
self
end
end
|
#get ⇒ any
24
25
26
|
# File 'lib/fear/success.rb', line 24
def get
@value
end
|
#inspect ⇒ String
Also known as:
to_s
101
102
103
|
# File 'lib/fear/success.rb', line 101
def inspect
"#<Fear::Success value=#{value.inspect}>"
end
|
#map ⇒ Try
76
77
78
79
80
|
# File 'lib/fear/success.rb', line 76
def map
super
rescue StandardError => error
Failure.new(error)
end
|
39
40
41
|
# File 'lib/fear/success.rb', line 39
def or_else
self
end
|
71
72
73
|
# File 'lib/fear/success.rb', line 71
def recover
self
end
|
#recover_with ⇒ Success
66
67
68
|
# File 'lib/fear/success.rb', line 66
def recover_with
self
end
|
#select {|value| ... } ⇒ Try
55
56
57
58
59
60
61
62
63
|
# File 'lib/fear/success.rb', line 55
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
29
30
31
|
# File 'lib/fear/success.rb', line 29
def success?
true
end
|
#to_either ⇒ Right
90
91
92
|
# File 'lib/fear/success.rb', line 90
def to_either
Right.new(value)
end
|