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.
22
23
24
|
# File 'lib/fear/success.rb', line 22
def initialize(value)
@value = value
end
|
Instance Method Details
#==(other) ⇒ Boolean
99
100
101
|
# File 'lib/fear/success.rb', line 99
def ==(other)
other.is_a?(Success) && value == other.value
end
|
#deconstruct ⇒ <any>
112
113
114
|
# File 'lib/fear/success.rb', line 112
def deconstruct
[value]
end
|
#failure? ⇒ false
37
38
39
|
# File 'lib/fear/success.rb', line 37
def failure?
false
end
|
#flat_map ⇒ Try
86
87
88
89
90
|
# File 'lib/fear/success.rb', line 86
def flat_map
super
rescue StandardError => error
Failure.new(error)
end
|
#flatten ⇒ Try
47
48
49
50
51
52
53
|
# File 'lib/fear/success.rb', line 47
def flatten
if value.is_a?(Try)
value.flatten
else
self
end
end
|
#get ⇒ any
27
28
29
|
# File 'lib/fear/success.rb', line 27
def get
@value
end
|
#inspect ⇒ String
Also known as:
to_s
104
105
106
|
# File 'lib/fear/success.rb', line 104
def inspect
"#<Fear::Success value=#{value.inspect}>"
end
|
#map ⇒ Try
79
80
81
82
83
|
# File 'lib/fear/success.rb', line 79
def map
super
rescue StandardError => error
Failure.new(error)
end
|
42
43
44
|
# File 'lib/fear/success.rb', line 42
def or_else
self
end
|
74
75
76
|
# File 'lib/fear/success.rb', line 74
def recover
self
end
|
#recover_with ⇒ Success
69
70
71
|
# File 'lib/fear/success.rb', line 69
def recover_with
self
end
|
#select {|value| ... } ⇒ Try
58
59
60
61
62
63
64
65
66
|
# File 'lib/fear/success.rb', line 58
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
32
33
34
|
# File 'lib/fear/success.rb', line 32
def success?
true
end
|
#to_either ⇒ Right
93
94
95
|
# File 'lib/fear/success.rb', line 93
def to_either
Right.new(value)
end
|