Created
November 30, 2012 14:37
-
-
Save jami-i/4176136 to your computer and use it in GitHub Desktop.
parse query params memo
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
object QueryParameter{ | |
def parse(query: String):Map[String, List[String]] = { | |
query | |
.split("&") | |
.map{_.split("=",2)} | |
.collect{ case p if p.length == 2 => (p(0), p(1))} | |
.foldLeft(Map.empty[String,List[String]])((z,n) => { | |
z + ( (n._1, (n._2 :: z.getOrElse(n._1,List.empty[String]))) ) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment