The general question is newb. Say I have 2 cards
val map1 = Map("ram"->"2gb", "size"->"15", "color"->"red", "fruit"->"strawberry") val map2 = Map("ram"->"2gb", "size"->"15", "color"->"red")
and I want to know if map1 contains completely map2 (the extra key / values โโin map1 are ok), what is a good way for Scala to do this?
The best I could come up with was to create my own function:
def doesMapContainMap(map1: Map[_,_], map2: Map[_,_]): Boolean = { var matchCount: Int = 0 map2 foreach { entry => { if (map1.exists(x => x._1 == entry._1 && x._2 == entry._2)) { matchCount += 1; } } }
This works (I think), but I wonder if there is anything better.
scala scala-collections map
Thomas
source share