Created
March 27, 2014 10:40
-
-
Save joescii/9804738 to your computer and use it in GitHub Desktop.
Replicating Racket's file->lines
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
object FileReaders { | |
object file { | |
def ->(contents: Seq[String]) = contents | |
} | |
object lines { | |
def apply(path:String) = scala.io.Source.fromFile(path).getLines().toSeq | |
} | |
} | |
object RunMe extends App { | |
import FileReaders._ | |
import java.io._ | |
def makeTemp = { | |
val temp = File.createTempFile("FileReaders", "txt") | |
temp.deleteOnExit() | |
val writer = new PrintStream(temp) | |
writer.println("A first line") | |
writer.println("A second line") | |
writer.println("And a third for good measure") | |
temp | |
} | |
val temp = makeTemp | |
val path = temp.getCanonicalPath | |
val contents = (file->lines(path)) | |
contents foreach (println(_)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment