Skip to content

Instantly share code, notes, and snippets.

@MasseGuillaume
Last active August 29, 2015 14:07
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 MasseGuillaume/8b273d5a792cf1ec85cc to your computer and use it in GitHub Desktop.
Save MasseGuillaume/8b273d5a792cf1ec85cc to your computer and use it in GitHub Desktop.
Uri Extractor
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