Class: Literal::Failure
Constant Summary
collapse
- EXCEPTION_DECONSTRUCT_KEYS =
[:detailed_message, :backtrace, :backtrace_locations, :cause, :full_message, :message, :exception]
- DECONSTRUCTION_TEMPLATE =
EXCEPTION_DECONSTRUCT_KEYS.each_with_object({}) do |key, hash|
hash[key] = -> (error) { error.send(key) if error.respond_to?(key) }
end
Instance Attribute Summary
Attributes inherited from Result
#value
Instance Method Summary
collapse
Methods inherited from Result
#call, #deconstruct, #initialize
Methods inherited from Monad
#handle
Instance Method Details
#bind ⇒ Object
51
|
# File 'lib/literal/failure.rb', line 51
def bind = self
|
#deconstruct_keys(keys) ⇒ Object
53
54
55
|
# File 'lib/literal/failure.rb', line 53
def deconstruct_keys(keys)
DECONSTRUCTION_TEMPLATE.slice(*keys).transform_values { |v| v.call(@value) }
end
|
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/literal/failure.rb', line 22
def failure(error)
if error === @value
if block_given?
yield(@value)
self
else
Literal::Some.new(@value)
end
else
block_given? ? self : Literal::Nothing
end
end
|
#failure? ⇒ true
16
|
# File 'lib/literal/failure.rb', line 16
def failure? = true
|
#filter ⇒ Object
47
|
# File 'lib/literal/failure.rb', line 47
def filter = self
|
#fmap ⇒ Object
50
|
# File 'lib/literal/failure.rb', line 50
def fmap = self
|
#inspect ⇒ String
10
|
# File 'lib/literal/failure.rb', line 10
def inspect = "Literal::Failure(#{@value.inspect})"
|
#lift(&block) ⇒ Object
57
58
59
|
# File 'lib/literal/failure.rb', line 57
def lift(*, &block)
block ? Literal::Lift.new(*, &block).with_failure(@value) : self
end
|
#lift!(&block) ⇒ Object
61
62
63
|
# File 'lib/literal/failure.rb', line 61
def lift!(*, &block)
block ? Literal::Lift.new(*, &block).with_failure!(@value) : self
end
|
#map(type) ⇒ Object
48
|
# File 'lib/literal/failure.rb', line 48
def map(type) = self
|
#map_failure(type = Exception) ⇒ Object
#raise! ⇒ Object
35
36
37
|
# File 'lib/literal/failure.rb', line 35
def raise!
raise(@value)
end
|
19
|
# File 'lib/literal/failure.rb', line 19
def success = Literal::Nothing
|
#success? ⇒ false
13
|
# File 'lib/literal/failure.rb', line 13
def success? = false
|
#then(type) ⇒ Object
49
|
# File 'lib/literal/failure.rb', line 49
def then(type) = self
|
#then_on_failure(result_type) ⇒ Object
#value_or {|@value| ... } ⇒ Object
43
44
45
|
# File 'lib/literal/failure.rb', line 43
def value_or
yield(@value)
end
|
#value_or_raise! ⇒ Object
39
40
41
|
# File 'lib/literal/failure.rb', line 39
def value_or_raise!
raise(@value)
end
|