Skip to content

Instantly share code, notes, and snippets.

@softprops
Created April 10, 2014 00:17
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 softprops/10332507 to your computer and use it in GitHub Desktop.
Save softprops/10332507 to your computer and use it in GitHub Desktop.
case class Url(
_host: String,
_path: Seq[String] = Seq.empty[String],
_query: Map[String, List[String]] = Map.empty[String, List[String]].withDefaultValue(Nil),
_fragment: Option[String] = None,
_scheme: Option[String] = None,
_port: Option[Int] = None) {
def host(host: String) = copy(_host = host)
def param(k: String, v: String) = copy(_query = _query + (k -> (v :: _query(k))))
def path(p: String) = copy(_path = p.split("/").filter(_.nonEmpty).toList)
def fragment(f: String) = copy(_fragment = Some(f))
def port(p: Int) = copy(_port = Some(p))
def scheme(s: String) = copy(_scheme = Some(s))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment