Scala: Pattern matching Seq[Nothing]
scala
Solution
Matching against an empty sequence looks like this:
val x: Seq[Nothing] = Vector()
x match {
case Seq() => println("empty sequence")
}
EDIT: Note that this is more general than `case Nil` since `Nil` is a subclass only of `List`, not `Seq` in general. Strangely, the compiler is ok with matching against `Nil` if the type is explicitly annotated as `Seq`, but it will complain if the type is any non-`List` subclass of `Seq`. Thus you can do this:
(Vector(): Seq[Int]) match { case Nil => "match" case _ => "no" }
but not this (fails with compile-time error):
Vector() match { case Nil => "match" case _ => "no" }
Problem
I am trying to match the case where a `Seq` contains `Nothing`. ``` models.Tasks.myTasks(idUser.toInt) match { case tasks => tasks.map { task => /* code here */ } case _ => "" //matches Seq(models.Tasks) } ``` How is `Seq[Nothing]` represented in pattern matching ?