gremlin-scala icon indicating copy to clipboard operation
gremlin-scala copied to clipboard

ScalaElement.valueMap ignores multi-properties

Open ThijsBroersen opened this issue 8 years ago • 2 comments

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))

ThijsBroersen avatar Nov 27 '17 09:11 ThijsBroersen

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?

mpollmeier avatar Nov 28 '17 01:11 mpollmeier

OMG, I forget I mentioned it already on gitter. I will make a PR next week.

ThijsBroersen avatar Nov 28 '17 10:11 ThijsBroersen