Created
April 11, 2011 20:47
-
-
Save seanparsons/914305 to your computer and use it in GitHub Desktop.
Easy parsing using regexes and pattern matching.
This file contains hidden or 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
// The variable data could easily be an Iterator from scala.io.Source instance, it will work just the same. | |
val data = List("Food,Count","Cake,9","Biscuits,2","Cookie,10") | |
val Parser = """([^,]+),(\d+)""".r | |
val entries = data.collect{case Parser(food,count) => (food, count.toInt)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment