Class: Literal::Success
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
85
86
87
88
89
|
# File 'lib/literal/success.rb', line 85
def bind
yield @value
rescue StandardError => e
Literal::Failure.new(e)
end
|
#deconstruct_keys(keys) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/literal/success.rb', line 91
def deconstruct_keys(keys)
if @value.respond_to?(:deconstruct_keys)
@value.deconstruct_keys(keys)
else
{ value: @value }
end
end
|
24
25
26
|
# File 'lib/literal/success.rb', line 24
def failure(error)
block_given? ? self : Literal::Nothing
end
|
#failure? ⇒ false
11
|
# File 'lib/literal/success.rb', line 11
def failure? = false
|
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/literal/success.rb', line 41
def filter
if yield(@value)
self
else
Literal::Failure.new(
RuntimeError.new(
"Filter condition not met."
)
)
end
end
|
#fmap ⇒ Object
81
82
83
|
# File 'lib/literal/success.rb', line 81
def fmap
Literal::Success.new(yield @value)
end
|
#inspect ⇒ String
5
|
# File 'lib/literal/success.rb', line 5
def inspect = "Literal::Success(#{@value.inspect})"
|
#lift(&block) ⇒ Object
99
100
101
|
# File 'lib/literal/success.rb', line 99
def lift(*, &block)
block ? Literal::Lift.new(*, &block).with_success(@value) : self
end
|
#lift!(&block) ⇒ Object
103
104
105
|
# File 'lib/literal/success.rb', line 103
def lift!(*, &block)
block ? Literal::Lift.new(*, &block).with_success!(@value) : self
end
|
#map_failure(value_type = Exception) ⇒ Object
107
|
# File 'lib/literal/success.rb', line 107
def map_failure(value_type = Exception) = self
|
#raise! ⇒ Object
28
|
# File 'lib/literal/success.rb', line 28
def raise! = self
|
14
15
16
17
18
19
20
21
|
# File 'lib/literal/success.rb', line 14
def success
if block_given?
yield(@value)
self
else
Literal::Some.new(@value)
end
end
|
#success? ⇒ true
8
|
# File 'lib/literal/success.rb', line 8
def success? = true
|
#then_on_failure(result_type) ⇒ Object
108
|
# File 'lib/literal/success.rb', line 108
def then_on_failure(result_type) = self
|
#value_or ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/literal/success.rb', line 32
def value_or
if block_given?
@value
else
raise Literal::ArgumentError, "Expected block."
end
end
|
#value_or_raise! ⇒ Object
30
|
# File 'lib/literal/success.rb', line 30
def value_or_raise! = @value
|