Packages

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
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ResourceIterator
  2. Closeable
  3. AutoCloseable
  4. VersionSpecificResourceIterator
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Concrete Value Members

  1. final def close(): Unit
    Definition Classes
    ResourceIterator → Closeable → AutoCloseable
  2. def collect[B](f: PartialFunction[A, B]): ResourceIterator[B]
  3. 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 that m < n, then only m elements will be dropped.

    No element will be consumed until the next next call.

  4. 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.

  5. def emap[E, S, B](f: (S) => Either[E, B])(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[Either[E, B]]
  6. def exists(p: (A) => Boolean): Boolean
  7. def filter(p: (A) => Boolean): ResourceIterator[A]
  8. def filterNot(pred: (A) => Boolean): ResourceIterator[A]
  9. def filterResult[E, S](p: (S) => Boolean)(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[A]
  10. def find(p: (A) => Boolean): Option[A]
  11. def flatMap[B](f: (A) => ResourceIterator[B]): ResourceIterator[B]
  12. def foldLeft[B](empty: B)(f: (B, A) => B): B
  13. def forall(p: (A) => Boolean): Boolean
  14. def foreach[U](f: (A) => U): Unit
  15. def hasDefiniteSize: Boolean
  16. final def hasNext: Boolean
  17. def isEmpty: Boolean
  18. def isTraversableAgain: Boolean
  19. def iterator: Iterator[A]
  20. def map[B](f: (A) => B): ResourceIterator[B]
  21. 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 underlying Either.

  22. final def next(): A
  23. 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.

  24. def scanLeft[B](z: B)(f: (B, A) => B): ResourceIterator[B]
  25. def slice(from: Int, until: Int): ResourceIterator[A]
  26. def take(n: Int): ResourceIterator[A]

    Restrict this resource to the next n elements, dropping whatever is left.

  27. 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.

  28. def to[F](factory: Factory[A, F]): F
  29. def toBuffer[AA >: A]: Buffer[AA]
  30. def toIndexedSeq: IndexedSeq[A]
  31. def toIterable: Iterable[A]
  32. def toList: List[A]
  33. def toSeq: Seq[A]
  34. def toSet[AA >: A]: Set[AA]
  35. def toVector: Vector[A]
  36. def withClose(f: () => Unit): ResourceIterator[A]

    Calls the specified function when the underlying resource is empty.

  37. def withFilter(p: (A) => Boolean): ResourceIterator[A]
  38. def zipWithIndex: ResourceIterator[(A, Int)]

Deprecated Value Members

  1. 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