class Dry::Types::Sum

@api public
Sum type

def self.operator = :|

def self.operator = :|

def call_safe(input, &block)

Other tags:
    Api: - private

Returns:
  • (Object) -

Parameters:
  • input (Object) --
def call_safe(input, &block)
  left.call_safe(input) { right.call_safe(input, &block) }
end

def call_unsafe(input)

Other tags:
    Api: - private

Returns:
  • (Object) -

Parameters:
  • input (Object) --
def call_unsafe(input)
  left.call_safe(input) { right.call_unsafe(input) }
end

def constrained(...)

Other tags:
    Api: - public

Other tags:
    See: Builder#constrained -

Returns:
  • (Constrained, Sum) -

Parameters:
  • options (Hash) --
def constrained(...)
  if optional?
    right.constrained(...).optional
  else
    super
  end
end

def meta(data = Undefined)

Other tags:
    Api: - public

Other tags:
    See: [Meta#meta] -
def meta(data = Undefined)
  if Undefined.equal?(data)
    optional? ? right.meta : super
  elsif optional?
    self.class.new(left, right.meta(data), **options)
  else
    super
  end
end

def optional? = primitive?(nil)

Other tags:
    Api: - public

Returns:
  • (Boolean) -
def optional? = primitive?(nil)

def primitive?(value)

Other tags:
    Api: - private

Returns:
  • (Boolean) -

Parameters:
  • value (Object) --
def primitive?(value)
  left.primitive?(value) || right.primitive?(value)
end

def try(input)

Other tags:
    Api: - public

Parameters:
  • input (Object) --
def try(input)
  left.try(input) do
    right.try(input) do |failure|
      if block_given?
        yield(failure)
      else
        failure
      end
    end
  end
end