Module: Dry::Monads::Validated::Mixin::Constructors

Included in:
Dry::Monads, Dry::Monads::Validated::Mixin
Defined in:
lib/dry/monads/validated.rb

Overview

Actual constructor methods

Instance Method Summary collapse

Instance Method Details

#Invalid(value) ⇒ Valdated::Invalid #Invalid(&block) ⇒ Valdated::Invalid

Invalid constructor

Overloads:

  • #Invalid(value) ⇒ Valdated::Invalid

    Parameters:

    • value (Object)

    Returns:

    • (Valdated::Invalid)
  • #Invalid(&block) ⇒ Valdated::Invalid

    Parameters:

    • block (Proc)

    Returns:

    • (Valdated::Invalid)

Raises:

  • (ArgumentError)

262
263
264
265
266
# File 'lib/dry/monads/validated.rb', line 262

def Invalid(value = Undefined, &block)
  v = Undefined.default(value, block)
  raise ArgumentError, 'No value given' if !value.nil? && v.nil?
  Invalid.new(v, RightBiased::Left.trace_caller)
end

#Valid(value) ⇒ Valdated::Valid #Valid(&block) ⇒ Valdated::Valid

Valid constructor

Overloads:

  • #Valid(value) ⇒ Valdated::Valid

    Parameters:

    • value (Object)

    Returns:

    • (Valdated::Valid)
  • #Valid(&block) ⇒ Valdated::Valid

    Parameters:

    • block (Proc)

    Returns:

    • (Valdated::Valid)

Raises:

  • (ArgumentError)

246
247
248
249
250
# File 'lib/dry/monads/validated.rb', line 246

def Valid(value = Undefined, &block)
  v = Undefined.default(value, block)
  raise ArgumentError, 'No value given' if !value.nil? && v.nil?
  Valid.new(v)
end