Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScalaElement.valueMap ignores multi-properties #224

Open
ThijsBroersen opened this issue Nov 27, 2017 · 2 comments
Open

ScalaElement.valueMap ignores multi-properties #224

ThijsBroersen opened this issue Nov 27, 2017 · 2 comments

Comments

@ThijsBroersen
Copy link
Contributor

ThijsBroersen commented Nov 27, 2017

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))
@mpollmeier
Copy link
Owner

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?

@ThijsBroersen
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants