Skip to content

Instantly share code, notes, and snippets.

@steveswing
Forked from ElectricCoffee/RichPath.scala
Created June 30, 2014 01:18
Show Gist options
  • Save steveswing/57fc3c8c53bf6ddc59d6 to your computer and use it in GitHub Desktop.
Save steveswing/57fc3c8c53bf6ddc59d6 to your computer and use it in GitHub Desktop.
import java.io.File
/**
* A completely OS-Agnostic way of dealing with java.io.File paths
*/
object RichPath {
sealed class RichBase[+A](left: A) {
/**
* Simple enrichment method designed to let you create a java.io.File
* by simply writing "folderA" / "folderB" / "folderC"
* @param right the right-side string
* @return new file with the given path
*/
def /(right: String): File = new File(left.toString, right)
}
/**
* Enriched File class, lets you write
* someFile / "String" to create a file with that kind of path
* @param left what's written on the left side of the /
*/
implicit class RichFile(left: File) extends RichBase(left)
/**
* Enriched String class, lets you write
* "someString" / "String" to create a file with that kind of path
* @param left what's written on the left side of the /
*/
implicit class RichString(left: String) extends RichBase(left) {
/**
* Provides a mean to turn a string into a file
* @return File based on string
*/
def toFile: File = new File(left)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment