想象一下我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"
}
Run Code Online (Sandbox Code Playgroud)
编译器抱怨说:
error: value Map is not a case class constructor, nor does it have an unapply/unapplySeq method
目前什么是模式匹配键值组合的最佳方法Map?