Created
March 22, 2011 23:49
-
-
Save kings13y/882354 to your computer and use it in GitHub Desktop.
Array pattern match using the sequence wildcard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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