gremlin-scala
gremlin-scala copied to clipboard
ScalaElement.valueMap ignores multi-properties
valueMap does not preserve multi-properties, the conversion to map only keeps a single value per key. I think valuemap should return List[A]
Current implementation:
def valueMap[A: DefaultsToAny]: Map[String, A] = valueMap[A](keys.toSeq.map(_.name): _*)
def valueMap[A: DefaultsToAny](keys: String*): Map[String, A] =
(properties[A](keys: _*) map (p ⇒ (p.key, p.value))).toMap
What about:
def valueMap[A: DefaultsToAny]: Map[String, List[A]] = valueMap[A](keys.toSeq.map(_.name): _*)
def valueMap[A: DefaultsToAny](keys: String*): Map[String, List[A]] =
(properties[A](keys: _*) groupBy (p => p.key()) mapValues (p ⇒ p.map(_.value()).toList))
as discussed in https://gitter.im/mpollmeier/gremlin-scala: you're right. in the majority of cases properties are actually single values, so maybe we should have an additional valueMapFlattened (please propose a better name) that still returns Map[String, A]. WDYT? also, mind sending a PR with a test?
OMG, I forget I mentioned it already on gitter. I will make a PR next week.