Basically I need to get a set of values from a map for a keys in a given list (in the same order keys are given).
val kv = Map("k3" -> "v3", "k1" -> "v1", "k2" -> "v2")
val ks = List("k1", "k2")
The best I could have improvised is foldRight over ks:
scala> (ks foldRight List[String]()) { (v, a) => kv(v) :: a }
res7: List[String] = List(v1, v2)
Are there any more convenient ways to do this in standard lib or just the shorter code, ideally something alike kv getVals ks? :)
Question is not so important of course, just trying to explore towards good style.
foldLeftbe a better option here? It would be a better style I think, because it is implemented by iteration while foldRight is implemented by recursion in List.scala.