Class: Resonad::Failure
Constant Summary
Constants inherited
from Resonad
Mixin, NIL_FAILURE, NIL_SUCCESS, VERSION
Constants included
from PublicMixin
PublicMixin::Failure, PublicMixin::Success
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Resonad
#and_then, #bad?, #failed?, #failure?, #if_bad, #if_failed, #if_failure, #if_ok, #if_success, #if_successful, #map_value, #ok?, #on_bad, #on_failed, #on_ok, #on_successful, #or_else, #otherwise, rescuing_from, #successful?, #when_bad, #when_failed, #when_failure, #when_ok, #when_success, #when_successful
#Failure, #Success, #failure, #success
Constructor Details
#initialize(error) ⇒ Failure
Returns a new instance of Failure.
79
80
81
82
|
# File 'lib/resonad.rb', line 79
def initialize(error)
@error = error
freeze
end
|
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
69
70
71
|
# File 'lib/resonad.rb', line 69
def error
@error
end
|
Class Method Details
.[](error = nil) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/resonad.rb', line 71
def self.[](error = nil)
if nil == error
NIL_FAILURE
else
new(error)
end
end
|
Instance Method Details
#deconstruct ⇒ Object
122
123
124
|
# File 'lib/resonad.rb', line 122
def deconstruct
[:failure, error]
end
|
#deconstruct_keys(_) ⇒ Object
126
127
128
|
# File 'lib/resonad.rb', line 126
def deconstruct_keys(_)
{ error: error }
end
|
#flat_map ⇒ Object
114
115
116
|
# File 'lib/resonad.rb', line 114
def flat_map
self
end
|
#flat_map_error {|error| ... } ⇒ Object
118
119
120
|
# File 'lib/resonad.rb', line 118
def flat_map_error
yield error
end
|
#map ⇒ Object
101
102
103
|
# File 'lib/resonad.rb', line 101
def map
self
end
|
#map_error ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/resonad.rb', line 105
def map_error
new_error = yield(error)
if new_error.__id__ == error.__id__
self
else
self.class.new(new_error)
end
end
|
#on_failure {|error| ... } ⇒ Object
92
93
94
95
|
# File 'lib/resonad.rb', line 92
def on_failure
yield error
self
end
|
#on_success ⇒ Object
88
89
90
|
# File 'lib/resonad.rb', line 88
def on_success
self
end
|
#success? ⇒ Boolean
84
85
86
|
# File 'lib/resonad.rb', line 84
def success?
false
end
|
#value ⇒ Object
97
98
99
|
# File 'lib/resonad.rb', line 97
def value
raise NonExistentValue, "Failure resonads do no have values"
end
|