class Dry::Types::Array::Member

@api public
Member arrays define their member type that is applied to each element

def call_safe(input)

Other tags:
    Api: - private

Returns:
  • (Array) -

Parameters:
  • input (Object) --
def call_safe(input)
  if primitive?(input)
    failed = false
    result = input.each_with_object([]) do |el, output|
      coerced = member.call_safe(el) { |out = el|
        failed = true
        out
      }
      output << coerced unless Undefined.equal?(coerced)
    end
    failed ? yield(result) : result
  else
    yield
  end
end

def call_unsafe(input)

Other tags:
    Api: - private

Returns:
  • (Array) -

Parameters:
  • input (Object) --
def call_unsafe(input)
  if primitive?(input)
    input.each_with_object([]) do |el, output|
      coerced = member.call_unsafe(el)
      output << coerced unless Undefined.equal?(coerced)
    end
  else
    super
  end
end

def constructor_type = ::Dry::Types::Array::Constructor

Other tags:
    Api: - private
def constructor_type = ::Dry::Types::Array::Constructor

def initialize(primitive, **options)

Other tags:
    Api: - private

Options Hash: (**options)
  • :member (Type) --

Parameters:
  • options (Hash) --
  • primitive (Class) --
def initialize(primitive, **options)
  @member = options.fetch(:member)
  super
end

def lax

Other tags:
    Api: - public

Returns:
  • (Lax) -
def lax
  Lax.new(Member.new(primitive, **options, member: member.lax, meta: meta))
end

def to_ast(meta: true)

Other tags:
    Api: - public

Other tags:
    See: Nominal#to_ast -
def to_ast(meta: true)
  if member.respond_to?(:to_ast)
    [:array, [member.to_ast(meta: meta), meta ? self.meta : EMPTY_HASH]]
  else
    [:array, [member, meta ? self.meta : EMPTY_HASH]]
  end
end

def try(input, &block) # rubocop:disable Metrics/PerceivedComplexity

Other tags:
    Api: - public

Returns:
  • (Result, Logic::Result) -

Other tags:
    Yieldreturn: -

Other tags:
    Yieldparam: failure -

Parameters:
  • block (#call, nil) --
  • input (Array, Object) --
def try(input, &block) # rubocop:disable Metrics/PerceivedComplexity
  if primitive?(input)
    output = []
    result = input.map { |el| member.try(el) }
    result.each do |r|
      output << r.input unless Undefined.equal?(r.input)
    end
    if result.all?(&:success?)
      success(output)
    else
      error = result.find(&:failure?).error
      failure = failure(output, error)
      block ? yield(failure) : failure
    end
  else
    failure = failure(input, CoercionError.new("#{input} is not an array"))
    block ? yield(failure) : failure
  end
end