Skip to content

Instantly share code, notes, and snippets.

@hamnis
Created August 9, 2011 11:41
Show Gist options
  • Save hamnis/1133826 to your computer and use it in GitHub Desktop.
Save hamnis/1133826 to your computer and use it in GitHub Desktop.
Implicit conversion
package com
import example.util.RichURI
import java.net.URI
package object example {
implicit def uri2RichURI(uri: URI): RichURI = RichURI(uri)
implicit def richURI2URI(richURI: RichURI): URI = richURI.uri
}
package com.example.util
import java.net.URI
case class RichURI(uri: URI) {
def getLastPathSegment = {
val uriAsString = uri.toString
val index = uriAsString.lastIndexOf("/")
if (index != -1) {
Some(uriAsString.substring(index + 1))
}
else {
None
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment