Trait/Object

kantan.codecs.resource

ResourceIterator

Related Docs: object ResourceIterator | package resource

Permalink

trait ResourceIterator[+A] extends TraversableOnce[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()
Linear Supertypes
java.io.Closeable, AutoCloseable, TraversableOnce[A], GenTraversableOnce[A], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ResourceIterator
  2. Closeable
  3. AutoCloseable
  4. TraversableOnce
  5. GenTraversableOnce
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def checkNext: Boolean

    Permalink

    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
  2. abstract def readNext(): A

    Permalink

    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
  3. abstract def release(): Unit

    Permalink

    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

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def /:[B](z: B)(op: (B, A) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  4. def :\[B](z: B)(op: (A, B) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. def addString(b: StringBuilder): StringBuilder

    Permalink
    Definition Classes
    TraversableOnce
  7. def addString(b: StringBuilder, sep: String): StringBuilder

    Permalink
    Definition Classes
    TraversableOnce
  8. def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder

    Permalink
    Definition Classes
    TraversableOnce
  9. def aggregate[B](z: ⇒ B)(seqop: (B, A) ⇒ B, combop: (B, B) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  10. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  11. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  12. final def close(): Unit

    Permalink
    Definition Classes
    ResourceIterator → Closeable → AutoCloseable
  13. def collect[B](f: PartialFunction[A, B]): ResourceIterator[B]

    Permalink
  14. def collectFirst[B](pf: PartialFunction[A, B]): Option[B]

    Permalink
    Definition Classes
    TraversableOnce
  15. def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit

    Permalink
    Definition Classes
    ResourceIterator → TraversableOnce → GenTraversableOnce
  16. def copyToArray[B >: A](xs: Array[B]): Unit

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  17. def copyToArray[B >: A](xs: Array[B], start: Int): Unit

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  18. def copyToBuffer[B >: A](dest: Buffer[B]): Unit

    Permalink
    Definition Classes
    TraversableOnce
  19. def count(p: (A) ⇒ Boolean): Int

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  20. def drop(n: Int): ResourceIterator[A]

    Permalink

    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.

  21. def dropWhile(p: (A) ⇒ Boolean): ResourceIterator[A]

    Permalink

    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.

  22. def emap[E, S, B](f: (S) ⇒ Either[E, B])(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[Either[E, B]]

    Permalink
  23. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  24. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  25. def exists(p: (A) ⇒ Boolean): Boolean

    Permalink
    Definition Classes
    ResourceIterator → TraversableOnce → GenTraversableOnce
  26. def filter(p: (A) ⇒ Boolean): ResourceIterator[A]

    Permalink
  27. def filterResult[E, S](p: (S) ⇒ Boolean)(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[A]

    Permalink
  28. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  29. def find(p: (A) ⇒ Boolean): Option[A]

    Permalink
    Definition Classes
    ResourceIterator → TraversableOnce → GenTraversableOnce
  30. def flatMap[B](f: (A) ⇒ ResourceIterator[B]): ResourceIterator[B]

    Permalink
  31. def fold[A1 >: A](z: A1)(op: (A1, A1) ⇒ A1): A1

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  32. def foldLeft[B](z: B)(op: (B, A) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  33. def foldRight[B](z: B)(op: (A, B) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  34. def forall(p: (A) ⇒ Boolean): Boolean

    Permalink
    Definition Classes
    ResourceIterator → TraversableOnce → GenTraversableOnce
  35. def foreach[U](f: (A) ⇒ U): Unit

    Permalink
    Definition Classes
    ResourceIterator → TraversableOnce → GenTraversableOnce
  36. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  37. def hasDefiniteSize: Boolean

    Permalink
    Definition Classes
    ResourceIterator → TraversableOnce → GenTraversableOnce
  38. final def hasNext: Boolean

    Permalink
  39. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  40. def isEmpty: Boolean

    Permalink
    Definition Classes
    ResourceIterator → TraversableOnce → GenTraversableOnce
  41. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  42. def isTraversableAgain: Boolean

    Permalink
    Definition Classes
    ResourceIterator → GenTraversableOnce
  43. def map[B](f: (A) ⇒ B): ResourceIterator[B]

    Permalink
  44. def mapResult[E, S, B](f: (S) ⇒ B)(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[Either[E, B]]

    Permalink

    Applies the specified function to the Right case of the underlying Either.

  45. def max[B >: A](implicit cmp: Ordering[B]): A

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  46. def maxBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B]): A

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  47. def min[B >: A](implicit cmp: Ordering[B]): A

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  48. def minBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B]): A

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  49. def mkString: String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  50. def mkString(sep: String): String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  51. def mkString(start: String, sep: String, end: String): String

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  52. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  53. final def next(): A

    Permalink
  54. def nonEmpty: Boolean

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  55. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  56. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  57. def product[B >: A](implicit num: Numeric[B]): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  58. def reduce[A1 >: A](op: (A1, A1) ⇒ A1): A1

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  59. def reduceLeft[B >: A](op: (B, A) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce
  60. def reduceLeftOption[B >: A](op: (B, A) ⇒ B): Option[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  61. def reduceOption[A1 >: A](op: (A1, A1) ⇒ A1): Option[A1]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  62. def reduceRight[B >: A](op: (A, B) ⇒ B): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  63. def reduceRightOption[B >: A](op: (A, B) ⇒ B): Option[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  64. def reversed: List[A]

    Permalink
    Attributes
    protected[this]
    Definition Classes
    TraversableOnce
  65. def safe[F](empty: ⇒ F)(f: (Throwable) ⇒ F): ResourceIterator[Either[F, A]]

    Permalink

    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.

  66. def seq: TraversableOnce[A]

    Permalink
    Definition Classes
    ResourceIterator → TraversableOnce → GenTraversableOnce
  67. def size: Int

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  68. def sum[B >: A](implicit num: Numeric[B]): B

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  69. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  70. def take(n: Int): ResourceIterator[A]

    Permalink

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

  71. def takeWhile(p: (A) ⇒ Boolean): ResourceIterator[A]

    Permalink

    Considers this resource to be empty as soon as an element is found that doesn't verify p.

  72. def to[Col[_]](implicit cbf: CanBuildFrom[Nothing, A, Col[A]]): Col[A]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  73. def toArray[B >: A](implicit arg0: ClassTag[B]): Array[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  74. def toBuffer[B >: A]: Buffer[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  75. def toIndexedSeq: IndexedSeq[A]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  76. def toIterable: Iterable[A]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  77. def toIterator: Iterator[A]

    Permalink
    Definition Classes
    ResourceIterator → GenTraversableOnce
  78. def toList: List[A]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  79. def toMap[T, U](implicit ev: <:<[A, (T, U)]): Map[T, U]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  80. def toSeq: Seq[A]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  81. def toSet[B >: A]: Set[B]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  82. def toStream: Stream[A]

    Permalink
    Definition Classes
    ResourceIterator → GenTraversableOnce
  83. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  84. def toTraversable: Traversable[A]

    Permalink
    Definition Classes
    ResourceIterator → TraversableOnce → GenTraversableOnce
  85. def toVector: Vector[A]

    Permalink
    Definition Classes
    TraversableOnce → GenTraversableOnce
  86. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  87. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  88. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  89. def withClose(f: () ⇒ Unit): ResourceIterator[A]

    Permalink

    Calls the specified function when the underlying resource is empty.

  90. def withFilter(p: (A) ⇒ Boolean): ResourceIterator[A]

    Permalink

Deprecated Value Members

  1. def flatMapResult[E, S, B](f: (S) ⇒ Either[E, B])(implicit ev: <:<[A, Either[E, S]]): ResourceIterator[Either[E, B]]

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 0.2.2) Use emap instead

Inherited from java.io.Closeable

Inherited from AutoCloseable

Inherited from TraversableOnce[A]

Inherited from GenTraversableOnce[A]

Inherited from AnyRef

Inherited from Any

Ungrouped