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

org.scalaquery.util.CloseableIterator.scala Maven / Gradle / Ivy

package org.scalaquery.util

import java.io.Closeable

/**
 * An Iterator with a close() method to close the underlying data source.
 */
trait CloseableIterator[+T] extends Iterator[T] with Closeable {

  override def close(): Unit

  final def use[R](f: (Iterator[T] => R)): R =
    try f(this) finally close()

  final def use[R](f: =>R): R =
    try f finally close()
}

object CloseableIterator {
  val empty: CloseableIterator[Nothing] = new CloseableIterator[Nothing] {
    def hasNext = false
    def next() = throw new NoSuchElementException("next on empty iterator")
    def close() {}
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy