0

I've two maps, and i need to know if all the elements in map1 are in map2 also. I think that using sets is a good idea but this doesn't work.

map1 = Map("provider" -> pepe, "consumer" -> pipo)
map2 = Map("provider" -> pepe, "consumer" -> pipo, "id" -> 1)

map1.toSet subsetOf map2.toSet

1 Answers1

1

You haven't specified what is the type of pepe and pipo but let's assume they've got the same type and it's String. When you use map1.toSet it would create a set with inferred type Set[(String, String)]. Your other map contains also integer so type would be Set[(String, Any)]. So your code won't compile because types don't match. One way to solve it would be just specifying type:

map1.toSet[(String, Any)].subsetOf(map2.toSet)
Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76