title: Loaner Pattern in Scala
body: <p><a href="http://www.manning.com/suereth/" rel="noreferrer">Scala in Depth</a> demonstrates the <em>Loaner Pattern</em>:</p>
  
  <pre><code>def readFile[T](f: File)(handler: FileInputStream =&gt; T): T = {
    val resource = new java.io.FileInputStream(f)
    try {
      handler(resource)
    } finally {
        resource.close()
    }
  }
  </code></pre>
  
  <p>Example usage:</p>
  
  <pre><code>readFile(new java.io.File("test.txt")) { input =&gt;
     println(input.readByte)
  }
  </code></pre>
  
  <p>This code appears simple and clear. What is an "anti-pattern" of the Loaner pattern in Scala so that I know how to avoid it?</p>