trait ResourceIterator[+A] extends VersionSpecificResourceIterator[A] with java.io.Closeable
Offers iterator-like access to IO resources.
For the most part, values of type ResourceIterator can be considered as iterators, with a few improvements.
First, they have a ResourceIterator.close()* method, which allows you to release the underlying resource when
needed. This is fairly important and part of the reason why working with Source.getLines
can be so aggravating.
Second, ResourceIterator.close()* is mostly not needed: whenever an IO error occurs or the underlying resource is empty, it will be closed automatically. Provided you intend to read the whole resource, you never need to explicitly close it. This covers non-obvious cases such as filtering or dropping elements.
You should be able to express most common causes for not reading the entire stream through standard combinators. For
example, "take the first n
elements" is take(n)
, or "take all odd elements" is filter(_ % 2 == 0)
. This
allows you to ignore the fact that the underlying resource needs to be closed. Should you ever find youself in a
situation when you just want to stop, however, ResourceIterator.close()* is available.
- Self Type
- ResourceIterator[A]
- Annotations
- @SuppressWarnings()
- Source
- ResourceIterator.scala
- Alphabetic
- By Inheritance
- ResourceIterator
- Closeable
- AutoCloseable
- VersionSpecificResourceIterator
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def checkNext: Boolean
Checks whether there are still elements to read in the underlying resource.
Checks whether there are still elements to read in the underlying resource.
This method must be pure: it's expected not to have side effects and never to throw exceptions.
- Attributes
- protected
- abstract def readNext(): A
Reads the next element in the underlying resource
Reads the next element in the underlying resource
This method is by definition side-effecting and allowed to throw exceptions.
- Attributes
- protected
- abstract def release(): Unit
Releases the underlying resource.
Releases the underlying resource.
While this method is side-effecting and allowed to throw exceptions, the current implementation will simply swallow them.
- Attributes
- protected
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def close(): Unit
- Definition Classes
- ResourceIterator → Closeable → AutoCloseable
- def collect[B](f: PartialFunction[A, B]): ResourceIterator[B]
- def drop(n: Int): ResourceIterator[A]
Drops the next
n
elements from the resource.Drops the next
n
elements from the resource.If the resource contains
m
elements such thatm < n
, then onlym
elements will be dropped.No element will be consumed until the next next call.
- def dropWhile(p: (A) => Boolean): ResourceIterator[A]
Drops elements from the resource until one is found that doesn't verify
p
or the resource is empty.Drops elements from the resource until one is found that doesn't verify
p
or the resource is empty.No element will be consumed until the next next call.
- def emap[E, S, B](f: (S) => Either[E, B])(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[Either[E, B]]
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exists(p: (A) => Boolean): Boolean
- def filter(p: (A) => Boolean): ResourceIterator[A]
- def filterNot(pred: (A) => Boolean): ResourceIterator[A]
- def filterResult[E, S](p: (S) => Boolean)(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[A]
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def find(p: (A) => Boolean): Option[A]
- def flatMap[B](f: (A) => ResourceIterator[B]): ResourceIterator[B]
- def foldLeft[B](empty: B)(f: (B, A) => B): B
- def forall(p: (A) => Boolean): Boolean
- def foreach[U](f: (A) => U): Unit
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hasDefiniteSize: Boolean
- final def hasNext: Boolean
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def isEmpty: Boolean
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isTraversableAgain: Boolean
- def iterator: Iterator[A]
- Definition Classes
- VersionSpecificResourceIterator
- def map[B](f: (A) => B): ResourceIterator[B]
- def mapResult[E, S, B](f: (S) => B)(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[Either[E, B]]
Applies the specified function to the
Right
case of the underlyingEither
. - final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def next(): A
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def safe[F](empty: => F)(f: (Throwable) => F): ResourceIterator[Either[F, A]]
Makes the current kantan.codecs.resource.ResourceIterator safe.
Makes the current kantan.codecs.resource.ResourceIterator safe.
This is achieved by catching all non-fatal exceptions and passing them to the specified
f
to turn into a failure type.This is meant to be used by the various kantan.* libraries that offer stream-like APIs: it allows them to wrap IO in a safe iterator and focus on dealing with decoding.
- empty
error value for when
next
is called on an empty iterator.- f
used to turn non-fatal exceptions into error types.
- def scanLeft[B](z: B)(f: (B, A) => B): ResourceIterator[B]
- def slice(from: Int, until: Int): ResourceIterator[A]
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def take(n: Int): ResourceIterator[A]
Restrict this resource to the next
n
elements, dropping whatever is left. - def takeWhile(p: (A) => Boolean): ResourceIterator[A]
Considers this resource to be empty as soon as an element is found that doesn't verify
p
. - def to[F](factory: Factory[A, F]): F
- Definition Classes
- VersionSpecificResourceIterator
- def toBuffer[AA >: A]: Buffer[AA]
- Definition Classes
- VersionSpecificResourceIterator
- def toIndexedSeq: IndexedSeq[A]
- Definition Classes
- VersionSpecificResourceIterator
- def toIterable: Iterable[A]
- Definition Classes
- VersionSpecificResourceIterator
- def toList: List[A]
- Definition Classes
- VersionSpecificResourceIterator
- def toSeq: Seq[A]
- Definition Classes
- VersionSpecificResourceIterator
- def toSet[AA >: A]: Set[AA]
- Definition Classes
- VersionSpecificResourceIterator
- def toString(): String
- Definition Classes
- AnyRef → Any
- def toVector: Vector[A]
- Definition Classes
- VersionSpecificResourceIterator
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withClose(f: () => Unit): ResourceIterator[A]
Calls the specified function when the underlying resource is empty.
- def withFilter(p: (A) => Boolean): ResourceIterator[A]
- def zipWithIndex: ResourceIterator[(A, Int)]
Deprecated Value Members
- def flatMapResult[E, S, B](f: (S) => Either[E, B])(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[Either[E, B]]
- Annotations
- @deprecated
- Deprecated
(Since version 0.2.2) Use emap instead