想象一下,我Map[String, String]
在 Scala 中有一个。
我想匹配地图中的全套键值对。
这样的事情应该是可能的
val record = Map("amenity" -> "restaurant", "cuisine" -> "chinese", "name" -> "Golden Palace")
record match {
case Map("amenity" -> "restaurant", "cuisine" -> "chinese") => "a Chinese restaurant"
case Map("amenity" -> "restaurant", "cuisine" -> "italian") => "an Italian restaurant"
case Map("amenity" -> "restaurant") => "some other restaurant"
case _ => "something else entirely"
}
编译器抱怨thulsy:
error: value Map is not a case class constructor, nor does it have an unapply/unapplySeq method
目前对 a 中的键值组合进行模式匹配的最佳方法是Map
什么?