As other posters noted, List(x) only matches a list of 1 element.
However, there is syntax for matching multiple elements:
def example(list: List[Int]) = list match { case Nil => println("Nil") case List(x @ _*) => println(x) } example(List(11, 3, -5, 5, 889, 955, 1024))
This is a fun thing that makes a difference. _* corresponds to the repeated parameter, and x @ says: "Associate this with x ."
The same thing works with any pattern matching that can match repeating elements (e.g. Array(x @ _*) or Seq(x @ _*) ). List(x @ _*) may also correspond to empty lists, although in this case we have already matched Nil.
You can also use _* to match the "rest", as in:
def example(list: List[Int]) = list match { case Nil => println("Nil") case List(x) => println(x) case List(x, xs @ _*) => println(x + " and then " + xs) }
source share