Skip to content

Instantly share code, notes, and snippets.

@kings13y
Created March 22, 2011 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kings13y/882354 to your computer and use it in GitHub Desktop.
Save kings13y/882354 to your computer and use it in GitHub Desktop.
Array pattern match using the sequence wildcard
val oneToFour = List(1, 2, 3, 4)
val odds = List(1, 3, 5, 7)
def findWhereSecondElemIsAThree(listOfInts: List[Int]) = listOfInts match {
case List(_, 3, _*) => "Found a list where second element == 3"
case List(_*) => "List with 0 or more elements"
}
findWhereSecondElemIsAThree(oneToFour)
findWhereSecondElemIsAThree(odds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment