Sha256: b1c1afac5469f540032230e93ce43af9d0c2d510267aef4682c75bd50cc440fc

Contents?: true

Size: 684 Bytes

Versions: 6

Compression:

Stored size: 684 Bytes

Contents

# frozen_string_literal: true

using SmartCore::Ext::BasicObjectAsObject

# @api public
# @since 0.3.0
SmartCore::Types::Variadic.define_type(:Tuple) do |type|
  type.runtime_attributes_checker do |runtime_attrs|
    runtime_attrs.any? && runtime_attrs.all? do |runtime_attr|
      runtime_attr.is_a?(::Class)
    end
  end

  type.define_checker do |value, tuple_signature|
    next false unless SmartCore::Types::Value::Array.valid?(value)
    next false if value.size != tuple_signature.size

    value.each_with_index.all? do |tuple_val, tuple_val_index|
      expected_tuple_type = tuple_signature.at(tuple_val_index)
      tuple_val.is_a?(expected_tuple_type)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
smart_types-0.8.0 lib/smart_core/types/variadic/tuple.rb
smart_types-0.7.1 lib/smart_core/types/variadic/tuple.rb
smart_types-0.7.0 lib/smart_core/types/variadic/tuple.rb
smart_types-0.6.0 lib/smart_core/types/variadic/tuple.rb
smart_types-0.4.0 lib/smart_core/types/variadic/tuple.rb
smart_types-0.3.0 lib/smart_core/types/variadic/tuple.rb