Last active
April 23, 2019 11:46
-
-
Save invkrh/e22167dfb73fcfff606e387504d6b709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Product(id: Int, tags: Set[String]) | |
val productList = Array(Product(0, Set("a")), Product(1, Set("a", "b"))) | |
val tagDict1: Map[String, mutable.HashSet[Product]] = productList. | |
flatMap(p => p.tags.map(_ -> p)). | |
groupBy(_._1). | |
mapValues(v => mutable.HashSet() ++ v.map(_._2)) | |
val tagDict2 = Map[String, mutable.HashSet[Product]]( | |
"a" -> mutable.HashSet(productList(0), productList(1)), | |
"b" -> mutable.HashSet(productList(1))) | |
println(tagDict1 == tagDict2) | |
println(tagDict1("a") eq tagDict1("a")) | |
println(tagDict2("a") eq tagDict2("a")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment