Class: Dry::Monads::Validated
- Inherits:
-
Object
- Object
- Dry::Monads::Validated
- Defined in:
- lib/dry/monads/validated.rb,
lib/dry/monads/maybe.rb,
lib/dry/monads/result.rb
Overview
Validated is similar to Result and represents an outcome of a validation.
The difference between Validated and Result is that the former implements
#apply
in a way that concatenates errors. This means that the error type
has to have +
implemented (be a semigroup). This plays nice with arrays and lists.
Also, List
Defined Under Namespace
Modules: Mixin Classes: Invalid, Valid
Class Method Summary collapse
-
.pure(value = Undefined, &block) ⇒ Object
Wraps a value with
Valid
.
Instance Method Summary collapse
-
#bind ⇒ Object
Bind/flat_map is not implemented.
-
#to_monad ⇒ Validated::Valid, Validated::Invalid
Returns self.
Class Method Details
.pure(value) ⇒ Validated::Valid .pure(&block) ⇒ Validated::Valid
Wraps a value with Valid
.
36 37 38 |
# File 'lib/dry/monads/validated.rb', line 36 def pure(value = Undefined, &block) Valid.new(Undefined.default(value, block)) end |
Instance Method Details
#bind ⇒ Object
Bind/flat_map is not implemented
50 51 52 53 |
# File 'lib/dry/monads/validated.rb', line 50 def bind(*) # See https://typelevel.org/cats/datatypes/validated.html for details on why raise NotImplementedError, "Validated is not a monad because it would violate the monad laws" end |
#to_monad ⇒ Validated::Valid, Validated::Invalid
Returns self.
44 45 46 |
# File 'lib/dry/monads/validated.rb', line 44 def to_monad self end |