title: returning a lazy val in Scala
body: <p>I have a function that looks like this:</p>
  
  <pre><code>package org.thimblr.io
  import java.io._
  object Local {
    def streamer(path: String) = () =&gt; new FileReader(path)
  }
  </code></pre>
  
  <p>This manages basically what I want to do, which is to return a function that opens a stream from a file when it's called. So client code can do this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>But what I'd really like is to return a lazy val that streams from a file once it's referenced, like this:</p>
  
  <pre><code>val planStream = Local.streamer("/home/someuser/.plan")
  //...passes the val on to somewhere else, without opening the file for reading yet
  val firstByte=planStream.read
  //...such that planStream was only just opened to allow the read
  </code></pre>
  
  <p>Is it possible to do something like this, return a lazy val, so that client code can treat it as a value rather than a function?</p>