All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cl.core.lang.Control.scala Maven / Gradle / Ivy

The newest version!
package cl.core.lang

import scala.language.reflectiveCalls

object Control {

  /**
   * Automatic closable resource management
   * (from the book, Beginning Scala, by David Pollak)
   */
  def using[A <: { def close(): Unit }, B](resource: A)(f: A => B): B =
    try {
      f(resource)
    } finally {
      if (resource != null) resource.close()
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy