Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Support type mapping on Hash and Array types

+12 -2
+5
lib/literal/types/array_type.rb
··· 15 15 "_Array(#{@type.inspect})" 16 16 end 17 17 18 + def map(&) 19 + new_type = yield(@type) 20 + Literal::Types::ArrayType.new(new_type) 21 + end 22 + 18 23 def ===(value) 19 24 Array === value && value.all?(@type) 20 25 end
+5
lib/literal/types/hash_type.rb
··· 16 16 "_Hash(#{@key_type.inspect}, #{@value_type.inspect})" 17 17 end 18 18 19 + def map(&) 20 + new_key_type, new_hash_type = yield(@key_type, @value_type) 21 + Literal::Types::HashType.new(new_key_type, new_hash_type) 22 + end 23 + 19 24 def ===(value) 20 25 return false unless Hash === value 21 26
+1 -1
lib/literal/types/union_type.rb
··· 91 91 self[key] or raise KeyError.new("Key not found: #{key.inspect}") 92 92 end 93 93 94 - def map(type, &) 94 + def map(&) 95 95 Literal::Types::UnionType.new([*@primitives.map(&), *@types.map(&)]) 96 96 end 97 97
+1 -1
test/types/_kind.test.rb
··· 31 31 assert _Kind(_Array(numeric_kind.type)) === _Array(1) 32 32 33 33 union_type = _Union(String, Integer) 34 - union_kind = union_type.map(Literal::Types::KindType) { |it| _Kind(it) } 34 + union_kind = union_type.map { |it| _Kind(it) } 35 35 36 36 assert union_kind === Integer 37 37 end