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.
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.
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.
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.
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.
Applies the specified function to the Right
case of the underlying Either
.
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.
error value for when next
is called on an empty iterator.
used to turn non-fatal exceptions into error types.
Restrict this resource to the next n
elements, dropping whatever is left.
Considers this resource to be empty as soon as an element is found that doesn't verify p
.
Calls the specified function when the underlying resource is empty.
(Since version 0.2.2) Use emap instead
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" istake(n)
, or "take all odd elements" isfilter(_ % 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.