In Scala, I'm trying to filter a map based on a unique property with the Map values.
case class Product(
item: Item,
)
productModels: Map[Int, Product]
How can I create a new Map (or filter productModels) to only contain values where Product.Item.someproperty is unique within the Map?
I've been trying foldLeft on productModels, but can't seem to get it. I'll keep trying but want to check with you all as well.
Thanks
ProductwithStringfor simplicity, you'd expectf ( Map(1 -> "foo", 2 -> "bar", 3 -> "foo", 4 -> "bippy")to outputMap(2 -> "bar", 4 -> "bippy") )since"foo"shows up as a value for keys1and3?Map(1 -> "foo", 2 -> "bar", 4 -> "bippy")because these are the unique values