Created
August 9, 2011 11:41
-
-
Save hamnis/1133826 to your computer and use it in GitHub Desktop.
Implicit conversion
This file contains hidden or 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
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 | |
} |
This file contains hidden or 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
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