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.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait Closeabletrait AutoCloseabletrait VersionSpecificResourceIterator[A]class Objecttrait Matchableclass AnyShow all
- Self type
Members list
Value members
Concrete methods
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.
Attributes
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.
Attributes
Applies the specified function to the Right
case of the underlying Either
.
Applies the specified function to the Right
case of the underlying Either
.
Attributes
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.
Value parameters
- empty
-
error value for when
next
is called on an empty iterator. - f
-
used to turn non-fatal exceptions into error types.
Attributes
Restrict this resource to the next n
elements, dropping whatever is left.
Restrict this resource to the next n
elements, dropping whatever is left.
Attributes
Considers this resource to be empty as soon as an element is found that doesn't verify p
.
Considers this resource to be empty as soon as an element is found that doesn't verify p
.
Attributes
Calls the specified function when the underlying resource is empty.
Calls the specified function when the underlying resource is empty.
Attributes
Deprecated methods
Attributes
- Deprecated
- true
Inherited methods
Attributes
- Inherited from:
- VersionSpecificResourceIterator
Attributes
- Inherited from:
- VersionSpecificResourceIterator
Attributes
- Inherited from:
- VersionSpecificResourceIterator
Attributes
- Inherited from:
- VersionSpecificResourceIterator
Attributes
- Inherited from:
- VersionSpecificResourceIterator
Attributes
- Inherited from:
- VersionSpecificResourceIterator
Attributes
- Inherited from:
- VersionSpecificResourceIterator
Attributes
- Inherited from:
- VersionSpecificResourceIterator
Attributes
- Inherited from:
- VersionSpecificResourceIterator