Class: Dry::Monads::Result::Success
- Inherits:
-
Dry::Monads::Result
- Object
- Dry::Monads::Result
- Dry::Monads::Result::Success
- Includes:
- Dry::Monads::RightBiased::Right
- Defined in:
- lib/dry/monads/result.rb,
lib/dry/monads/maybe.rb,
lib/dry/monads/validated.rb
Overview
Represents a value of a successful operation.
Instance Attribute Summary
Attributes inherited from Dry::Monads::Result
Class Method Summary collapse
-
.[](*value) ⇒ Object
Shortcut for Success().
Instance Method Summary collapse
-
#alt_map(_ = nil) ⇒ Result::Success
Ignores values and returns self, see Failure#alt_map.
-
#either(f, _) ⇒ Any
Returns result of applying first function to the internal value.
-
#failure? ⇒ Boolean
Returns false.
-
#flip ⇒ Result::Failure
Transforms to a Failure instance.
-
#fmap ⇒ Result::Success
Does the same thing as #bind except it also wraps the value in an instance of Result::Success monad.
-
#initialize(value) ⇒ Success
constructor
A new instance of Success.
-
#result(_, f) ⇒ Object
Apply the second function to value.
-
#success? ⇒ Boolean
Returns true.
- #to_maybe ⇒ Maybe
- #to_s ⇒ String (also: #inspect)
-
#to_validated ⇒ Validated::Valid
Transforms to Validated.
Methods included from Dry::Monads::RightBiased::Right
#===, #and, #apply, #bind, #deconstruct, #deconstruct_keys, #discard, #flatten, included, #or, #or_fmap, #tee, #value!, #value_or, #|
Methods inherited from Dry::Monads::Result
#monad, pure, #to_monad, #to_result
Methods included from Transformer
Constructor Details
#initialize(value) ⇒ Success
Returns a new instance of Success.
72 73 74 75 |
# File 'lib/dry/monads/result.rb', line 72 def initialize(value) super() @value = value end |
Class Method Details
Instance Method Details
#alt_map(_ = nil) ⇒ Result::Success
Ignores values and returns self, see Failure#alt_map
129 |
# File 'lib/dry/monads/result.rb', line 129 def alt_map(_ = nil, &) = self |
#either(f, _) ⇒ Any
Returns result of applying first function to the internal value.
107 |
# File 'lib/dry/monads/result.rb', line 107 def either(f, _) = f.(success) |
#failure? ⇒ Boolean
Returns false
83 |
# File 'lib/dry/monads/result.rb', line 83 def failure? = false |
#flip ⇒ Result::Failure
Transforms to a Failure instance
122 123 124 |
# File 'lib/dry/monads/result.rb', line 122 def flip Failure.new(@value, RightBiased::Left.trace_caller) end |
#fmap ⇒ Result::Success
Does the same thing as #bind except it also wraps the value in an instance of Result::Success monad. This allows for easier chaining of calls.
97 |
# File 'lib/dry/monads/result.rb', line 97 def fmap(...) = Success.new(bind(...)) |
#result(_, f) ⇒ Object
Apply the second function to value.
80 |
# File 'lib/dry/monads/result.rb', line 80 def result(_, f) = f.(@value) |
#success? ⇒ Boolean
Returns true
86 |
# File 'lib/dry/monads/result.rb', line 86 def success? = true |
#to_maybe ⇒ Maybe
359 360 361 362 |
# File 'lib/dry/monads/maybe.rb', line 359 def to_maybe warn "Success(nil) transformed to None" if @value.nil? ::Dry::Monads::Maybe(@value) end |
#to_s ⇒ String Also known as: inspect
110 111 112 113 114 115 116 |
# File 'lib/dry/monads/result.rb', line 110 def to_s if Unit.equal?(@value) "Success()" else "Success(#{@value.inspect})" end end |
#to_validated ⇒ Validated::Valid
Transforms to Validated
280 |
# File 'lib/dry/monads/validated.rb', line 280 def to_validated = Validated::Valid.new(value!) |