Last active
August 29, 2015 14:07
-
-
Save MasseGuillaume/8b273d5a792cf1ec85cc to your computer and use it in GitHub Desktop.
Uri Extractor
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
case class Uri( | |
scheme: String, user: Option[String], host: String, port: Option[Int], | |
path: List[String], query: List[String]) | |
object Uri { | |
def unapply(uri: String): Option[Uri] = { | |
scala.util.Try(new java.net.URI(uri)).map{ v => | |
Some(new Uri(v.getScheme, Option(v.getUserInfo), v.getHost, Option(v.getPort), | |
v.getRawPath.split("/").to[List], v.getRawQuery.split("&").to[List])) | |
}.getOrElse(None) | |
} | |
} | |
"test" match { | |
case Uri(scheme, user, host, port, path, query) => scheme | |
// ^ too many patterns for object Uri offering Uri: expected 1, found 6 | |
case _ => "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment