Sha256: 699e2da759270410f9d0f89237bb428fe04fc6198d25bff4adcca24231d22b5e
Contents?: true
Size: 1.04 KB
Versions: 2
Compression:
Stored size: 1.04 KB
Contents
require 'dry/data/type/hash' require 'dry/data/type/array' require 'dry/data/sum_type' module Dry module Data class Type attr_reader :constructor attr_reader :primitive def self.[](primitive) if primitive == ::Array Type::Array elsif primitive == ::Hash Type::Hash else Type end end def self.strict_constructor(primitive, input) if input.is_a?(primitive) input else raise TypeError, "#{input.inspect} has invalid type" end end def self.passthrough_constructor(input) input end def initialize(constructor, primitive) @constructor = constructor @primitive = primitive end def name primitive.name end def call(input) constructor[input] end alias_method :[], :call def valid?(input) input.instance_of?(primitive) end def |(other) Data.SumType(self, other) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dry-data-0.1.0 | lib/dry/data/type.rb |
dry-data-0.0.1 | lib/dry/data/type.rb |