Last active
August 29, 2015 14:16
-
-
Save frgomes/bbefd9ae01bfa32f7a57 to your computer and use it in GitHub Desktop.
Scala - String to an absolute File
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
object FileSystemConverters extends FileSystemConverters | |
trait FileSystemConverters { | |
import java.io.File | |
implicit class RichOptionString2OptionFile(path: Option[String]) { | |
implicit def asFile: Option[File] = | |
Option( | |
path | |
.getOrElse(".") | |
.asFile) | |
} | |
implicit class RichString2File(path: String) { | |
implicit def asFile: File = | |
new File( | |
path | |
.replaceFirst( | |
"^~", | |
System.getProperty("user.home"))) | |
.getAbsoluteFile | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment