I have a function that looks like this:
package org.thimblr.io
import java.io._
object Local {
def streamer(path: String) = () => new FileReader(path)
}
This basically governs what I want to do to return a function that opens a stream from a file when it is called. So client code can do this:
val planStreamSource = Local.streamer("/home/someuser/.plan")
//...passes the function on to somewhere else
val planStream = planStreamSource()
val firstByte = planStream.read
//can now read from planStream
But I would really like to return a lazy val that flows from the file after its link, for example:
val planStream = Local.streamer("/home/someuser/.plan")
val firstByte=planStream.read
Is it possible to do something like this, return a lazy val so that the client code can consider it as a value, not a function?
source
share