Class: Dry::Monads::Validated Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/monads/validated.rb,
lib/dry/monads/maybe.rb,
lib/dry/monads/result.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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#traverse implicitly uses a block that wraps errors with a list so that you don't have to do it manually.

Examples:

using with List

List::Validated[Valid('London'), Invalid(:name_missing), Invalid(:email_missing)]
# => Invalid(List[:name_missing, :email_missing])

with valid results

List::Validated[Valid('London'), Valid('John')]
# => Valid(List['London', 'John'])

Direct Known Subclasses

Invalid, Valid

Defined Under Namespace

Modules: Mixin Classes: Invalid, Valid

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pure(value) ⇒ Validated::Valid .pure(&block) ⇒ Validated::Valid

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.

Wraps a value with Valid.

Overloads:



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

#bindObject

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.

Bind/flat_map is not implemented

Raises:

  • (NotImplementedError)


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_monadValidated::Valid, Validated::Invalid

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 self.



44
45
46
# File 'lib/dry/monads/validated.rb', line 44

def to_monad
  self
end