I have a map of entries of type Map[String, String] and a lookup map of type Map[String, Map[String, String]]. My goal is to look in the first map for a match in the second map, once I have a key match I have to replace the value in the first dictionary with the look up of the second dictionary. The example will clear things up.
I've come up with an algorithm so far but I am getting a strange answer of Some(e) and Some(t).
The first entry map is the following:
val entries = Map("fruit" -> "aaa", "animal" -> "bbb", "person" -> "jjj")
The second map is the following:
val lookup = Map("fruit" -> Map("ccc" -> "orange", "aaa" -> "apple"),
"animal" -> Map("zzz" -> "dog", "bbb" -> "cat"))
The result I am expecting is the following (Note: "person" was correctly not included in the result as there is no match for it):
val result = Map("fruit" -> "apple", "animal" -> "cat")
The algorithm I came up with is the following:
val res = for{ (k, ev) <- entries
lv <- lookup.get(k).get(ev)} yield (k, lv)
this algorithm gives me the following result and I have no idea why:
Map(fruit -> e, animal -> t)
Where is the e and t coming from?