lib/grumlin/typing.rb in grumlin-0.14.5 vs lib/grumlin/typing.rb in grumlin-0.15.0

- old
+ new

@@ -1,20 +1,21 @@ # frozen_string_literal: true module Grumlin module Typing TYPES = { - "g:List" => ->(value) { value.map { |item| cast(item) } }, - "g:Set" => ->(value) { Set.new(value.map { |item| cast(item) }) }, + "g:List" => ->(value) { cast_list(value) }, + "g:Set" => ->(value) { cast_list(value).to_set }, "g:Map" => ->(value) { cast_map(value) }, "g:Vertex" => ->(value) { cast_entity(Grumlin::Vertex, value) }, "g:Edge" => ->(value) { cast_entity(Grumlin::Edge, value) }, "g:Path" => ->(value) { cast_entity(Grumlin::Path, value) }, + "g:Traverser" => ->(value) { cast_entity(Traverser, value) }, + "g:Property" => ->(value) { cast_entity(Property, value) }, "g:Int64" => ->(value) { cast_int(value) }, "g:Int32" => ->(value) { cast_int(value) }, "g:Double" => ->(value) { cast_double(value) }, - "g:Traverser" => ->(value) { cast(value[:value]) }, # TODO: wtf is bulk? "g:Direction" => ->(value) { value }, # "g:VertexProperty"=> ->(value) { value }, # TODO: implement me "g:T" => ->(value) { value.to_sym } }.freeze @@ -70,9 +71,18 @@ raise UnknownMapKey, key, value end.transform_values { |v| cast(v) } rescue ArgumentError raise TypeError, "#{value} cannot be casted to Hash" + end + + def cast_list(value) + value.each_with_object([]) do |item, result| + casted_value = cast(item) + next (result << casted_value) unless casted_value.instance_of?(Traverser) + + casted_value.bulk.times { result << casted_value.value } + end end end end end