How do you pattern match an empty Map?
Map
doesn't provide any extractor with unapply()/unapplySeq()
methods out of the box, so it is impossible to match key-value pairs it in pattern matching. But if you need only to match if map is empty you can:
val map = Map.empty[String, String]
val result = map match {
case m:Map[String, String] if m.isEmpty => false
case _ => true
}
println(result)
outputs:
false