class Lithic::Internal::Type::ArrayOf

Array of items of a given type.
@generic Elem
@abstract
@api private

def self.[](...) = new(...)

Returns:
  • (self) -

Options Hash: (**spec)
  • :"nil?" (Boolean) --
  • :union (Proc) --
  • :enum (Proc) --
  • :const (NilClass, TrueClass, FalseClass, Integer, Float, Symbol) --

Parameters:
  • spec (Hash{Symbol=>Object}) -- .
  • type_info (Hash{Symbol=>Object}, Proc, Lithic::Internal::Type::Converter, Class) --

Overloads:
  • [](type_info, spec = {})
def self.[](...) = new(...)

def ==(other)

Returns:
  • (Boolean) -

Parameters:
  • other (Object) --

Other tags:
    Api: - public
def ==(other)
  # rubocop:disable Layout/LineLength
  other.is_a?(Lithic::Internal::Type::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type
  # rubocop:enable Layout/LineLength
end

def ===(other) = other.is_a?(Array) && other.all?(item_type)

Returns:
  • (Boolean) -

Parameters:
  • other (Object) --

Other tags:
    Api: - public
def ===(other) = other.is_a?(Array) && other.all?(item_type)

def coerce(value, state:)

Returns:
  • (Array, Object) -
    Options Hash: (**state)
    • :branched (Integer) --
    • :exactness (Hash{Symbol=>Object}) --
    • :strictness (Boolean, :strong) --

    Parameters:
    • state (Hash{Symbol=>Object}) -- .
    • value (Array, Object) --
      Other tags:
        Api: - private
      def coerce(value, state:)
        exactness = state.fetch(:exactness)
        unless value.is_a?(Array)
          exactness[:no] += 1
          return value
        end
        target = item_type
        exactness[:yes] += 1
        value
          .map do |item|
            case [nilable?, item]
            in [true, nil]
              exactness[:yes] += 1
              nil
            else
              Lithic::Internal::Type::Converter.coerce(target, item, state: state)
            end
          end
      end

      def dump(value, state:)

      Returns:
      • (Array, Object) -
        Options Hash: (**state)
        • :can_retry (Boolean) --

        Parameters:
        • state (Hash{Symbol=>Object}) -- .
        • value (Array, Object) --
          Other tags:
            Api: - private
          def dump(value, state:)
            target = item_type
            if value.is_a?(Array)
              value.map do
                Lithic::Internal::Type::Converter.dump(target, _1, state: state)
              end
            else
              super
            end
          end

          def hash = [self.class, item_type].hash

          Returns:
          • (Integer) -

          Other tags:
            Api: - public
          def hash = [self.class, item_type].hash

          def initialize(type_info, spec = {})

          Options Hash: (**spec)
          • :"nil?" (Boolean) --
          • :union (Proc) --
          • :enum (Proc) --
          • :const (NilClass, TrueClass, FalseClass, Integer, Float, Symbol) --

          Parameters:
          • spec (Hash{Symbol=>Object}) -- .
          • type_info (Hash{Symbol=>Object}, Proc, Lithic::Internal::Type::Converter, Class) --

          Other tags:
            Api: - private
          def initialize(type_info, spec = {})
            @item_type_fn = Lithic::Internal::Type::Converter.type_info(type_info || spec)
            @nilable = spec.fetch(:nil?, false)
          end

          def inspect(depth: 0)

          Returns:
          • (String) -

          Parameters:
          • depth (Integer) --

          Other tags:
            Api: - private
          def inspect(depth: 0)
            items = Lithic::Internal::Type::Converter.inspect(item_type, depth: depth.succ)
            "#{self.class}[#{[items, nilable? ? 'nil' : nil].compact.join(' | ')}]"
          end

          def item_type = @item_type_fn.call

          Returns:
          • (generic) -

          Other tags:
            Api: - private
          def item_type = @item_type_fn.call

          def nilable? = @nilable

          Returns:
          • (Boolean) -

          Other tags:
            Api: - private
          def nilable? = @nilable

          def to_sorbet_type

          Returns:
          • (Object) -

          Other tags:
            Api: - private
          def to_sorbet_type
            T::Array[Lithic::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(item_type)]
          end