Class: Dry::Types::Result
- Inherits:
-
Object
- Object
- Dry::Types::Result
- Defined in:
- lib/dry/types/result.rb,
lib/dry/types/extensions/monads.rb
Overview
Monad extension for Result
Defined Under Namespace
Instance Attribute Summary collapse
- #input ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(input) ⇒ Result
constructor
private
A new instance of Result.
-
#to_monad ⇒ Dry::Monads::Success, Dry::Monads::Failure
Turn result into a monad.
Constructor Details
#initialize(input) ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Result.
17 18 19 |
# File 'lib/dry/types/result.rb', line 17 def initialize(input) @input = input end |
Instance Attribute Details
#input ⇒ Object (readonly)
12 13 14 |
# File 'lib/dry/types/result.rb', line 12 def input @input end |
Instance Method Details
#to_monad ⇒ Dry::Monads::Success, Dry::Monads::Failure
Turn result into a monad
This makes result objects work with dry-monads (or anything with a compatible interface)
25 26 27 28 29 30 31 |
# File 'lib/dry/types/extensions/monads.rb', line 25 def to_monad if success? Success(input) else Failure([error, input]) end end |