List patterns
Lists and the values they contain can be pattern matched on in case expressions.
List patterns match on specific lengths of lists. The pattern []
matches an empty list, and the pattern [_]
matches a list with
one element. They will not match on lists with other lengths.
The spread pattern ..
can be used to match the rest of the list.
The pattern [1, ..]
matches any list that starts with
1
. The pattern [_, _, ..]
matches any list that has
at least two elements.