class Dry::Monads::Validated
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
<Validated>#traverse implicitly uses a block that wraps errors with a list so that you don’t have to do it manually.
@example using with List
List::Validated[Valid('London'), Invalid(:name_missing), Invalid(:email_missing)] # => Invalid(List[:name_missing, :email_missing])
@example with valid results
List::Validated[Valid('London'), Valid('John')] # => Valid(List['London', 'John'])
Public Class Methods
pure(value = Undefined, &block)
click to toggle source
Wraps a value with ‘Valid`.
@overload pure(value)
@param value [Object] value to be wrapped with Valid @return [Validated::Valid]
@overload pure(&block)
@param block [Object] block to be wrapped with Valid @return [Validated::Valid]
# File lib/dry/monads/validated.rb, line 34 def pure(value = Undefined, &block) Valid.new(Undefined.default(value, block)) end
Public Instance Methods
bind(*)
click to toggle source
Bind/flat_map is not implemented
# File lib/dry/monads/validated.rb, line 48 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()
click to toggle source
Returns self.
@return [Validated::Valid, Validated::Invalid
]
# File lib/dry/monads/validated.rb, line 42 def to_monad self end