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

au.csiro.pbdava.ssparkle.common.utils.LoanUtils.scala Maven / Gradle / Ivy

The newest version!
package au.csiro.pbdava.ssparkle.common.utils

import java.io.Closeable

import scala.io.Source

object LoanUtils {

  def withSource[R](src: Source)(func: Source => R): R = {
    try {
      func(src)
    } finally {
      src.close()
    }
  }

  def withCloseable[C <: Closeable, R](cl: C)(func: C => R): R = {
    try {
      func(cl)
    } finally {
      if (cl != null) {
        cl.close()
      }
    }
  }

  def withResource[C <: AutoCloseable, R](cl: C)(func: C => R): R = {
    try {
      func(cl)
    } finally {
      cl.close()
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy