My goal is to create two maps with keys all from a Seq[String].
For example, given:
val keys = Seq("key1", "key2")
I would like to get:
val map1 = Map("key1" -> List("something I get using key1"), "key2" -> List("something I get using key2"))
val map2 = Map("key1" -> List("some other stuff I get using key1"), "key2" -> List("some other stuff I get using key2"))
I've got a solution as below, but, given how cluttered and long this solution is, I feel like there must be a better/cleaner/more Scala-like approach.
Is there something I can do better in my solution? Appreciate the help in advanced!
val test = Seq("a", "b")
val (map1, map2) =
(for (key <- test) yield {
((key -> List("some stuff with key")), (key -> List("some other stuff with key")))
}).unzip match {
case (seq1: Seq[(String, List[String])], seq2: Seq[(String, List[String])]) => {
(seq1.toMap, seq2.toMap)
}
case _ => (Map(), Map())
}
EDIT: Dima's solution below is definitely what I will go with since it's much simpler/easier to read, but my question here is more of is there a Scala way to avoid running .map twice on the same set of seq.