Class: Dry::Monads::Result
- Inherits:
-
Object
- Object
- Dry::Monads::Result
- Includes:
- Transformer
- Defined in:
- lib/dry/monads/result.rb,
lib/dry/monads/maybe.rb,
lib/dry/monads/validated.rb,
lib/dry/monads/result/fixed.rb
Overview
Represents an operation which either succeeded or failed.
Defined Under Namespace
Modules: Mixin Classes: Failure, Fixed, Success
Instance Attribute Summary collapse
-
#failure ⇒ Object
readonly
Error.
-
#success ⇒ Object
readonly
Successful result.
Class Method Summary collapse
-
.pure(value = Undefined, &block) ⇒ Object
Wraps the given value with Success.
Instance Method Summary collapse
-
#monad ⇒ Monad
Returns the Result monad.
-
#to_monad ⇒ Result::Success, Result::Failure
Returns self.
-
#to_result ⇒ Result::Success, Result::Failure
Returns self, added to keep the interface compatible with other monads.
Methods included from Transformer
Instance Attribute Details
#failure ⇒ Object (readonly)
Returns Error.
16 17 18 |
# File 'lib/dry/monads/result.rb', line 16 def failure @failure end |
#success ⇒ Object (readonly)
Returns Successful result.
13 14 15 |
# File 'lib/dry/monads/result.rb', line 13 def success @success end |
Class Method Details
.pure(value) ⇒ Result::Success .pure(&block) ⇒ Result::Success
Wraps the given value with Success.
29 30 31 |
# File 'lib/dry/monads/result.rb', line 29 def pure(value = Undefined, &block) Success.new(Undefined.default(value, block)) end |
Instance Method Details
#monad ⇒ Monad
Returns the Result monad. This is how we’re doing polymorphism in Ruby 😕
52 53 54 |
# File 'lib/dry/monads/result.rb', line 52 def monad Result end |
#to_monad ⇒ Result::Success, Result::Failure
Returns self.
44 45 46 |
# File 'lib/dry/monads/result.rb', line 44 def to_monad self end |
#to_result ⇒ Result::Success, Result::Failure
Returns self, added to keep the interface compatible with other monads.
37 38 39 |
# File 'lib/dry/monads/result.rb', line 37 def to_result self end |