Interface CloseableIterator<T>

  • Type Parameters:
    T - the type of element being iterated on
    All Superinterfaces:
    AutoCloseable, io.vavr.collection.Foldable<T>, Iterable<T>, io.vavr.collection.Iterator<T>, Iterator<T>, io.vavr.collection.Traversable<T>, io.vavr.Value<T>
    All Known Implementing Classes:
    CloseableIterator.Wrapper

    public interface CloseableIterator<T>
    extends io.vavr.collection.Iterator<T>, AutoCloseable
    An iterator which may be derived from resources that should be closed once the iterator is no longer needed. This is used in the local runner to make it possible to iterate from partitions stored on disk and close the file descriptors as soon as iteration stops.
    The Java 8 Stream API is often recommended as a closeable "iterator-like" API but in our case it cannot be used because in some circumstances it buffers the stream, forcing the loading of an entire partition in memory while only the first few rows in it are actually needed.
    Like in the Java 8 Stream API, some methods return a new iterator and some others are a terminal action. Users should only close the iterator after using a terminal action, not after using a method that returns a new iterator. The derived iterator itself should be closed when a terminal action is called on it, and that will recursively call the close() method of the original iterator. Methods which derive an iterator from multiple iterators will close all the underlying iterators when they are closed themselves. For this reason, one should not derive multiple iterators from the same iterator, as they are using the same underlying resources.
    • Method Detail

      • hasNext

        boolean hasNext()
        Checks if the iterator contains a next element. If this returns false, the iterator should already be closed: it is not necessary to call close() after that.
        Specified by:
        hasNext in interface Iterator<T>
      • next

        T next()
        Returns the next element in the stream if there is one available. This may not be called after calling close().
        Specified by:
        next in interface Iterator<T>
      • close

        void close()
        Releases all resources underpinning this iterator. Calling this method multiple times is allowed but calling it only once is sufficient. The next() method may not be called after this one is called.
        Specified by:
        close in interface AutoCloseable
      • wrapping

        static <T> CloseableIterator<T> wrapping​(io.vavr.collection.Iterator<? extends T> ts)
      • collect

        default <R> CloseableIterator<R> collect​(io.vavr.PartialFunction<? super T,​? extends R> partialFunction)
        Specified by:
        collect in interface io.vavr.collection.Iterator<T>
        Specified by:
        collect in interface io.vavr.collection.Traversable<T>
      • chop

        default io.vavr.collection.Iterator<io.vavr.collection.Iterator<T>> chop​(io.vavr.collection.Iterator<Integer> lengths)
        Consumes the iterator by splitting it into chunks of the desired length. The returned iterators are not closeable so the parent iterator should be closed directly. Also, the iterators returned should be consumed in the order they are returned if the chunks are intended to be contiguous.
        Parameters:
        lengths - the lengths of the desired chunks
      • intersperse

        default CloseableIterator<T> intersperse​(T element)
        Specified by:
        intersperse in interface io.vavr.collection.Iterator<T>
      • zip

        @Deprecated
        default <U> io.vavr.collection.Iterator<io.vavr.Tuple2<T,​U>> zip​(Iterable<? extends U> that)
        Deprecated.
        This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
        Specified by:
        zip in interface io.vavr.collection.Iterator<T>
        Specified by:
        zip in interface io.vavr.collection.Traversable<T>
      • zipWith

        @Deprecated
        default <U,​R> io.vavr.collection.Iterator<R> zipWith​(Iterable<? extends U> that,
                                                                   BiFunction<? super T,​? super U,​? extends R> mapper)
        Deprecated.
        This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
        Specified by:
        zipWith in interface io.vavr.collection.Iterator<T>
        Specified by:
        zipWith in interface io.vavr.collection.Traversable<T>
      • zipAll

        @Deprecated
        default <U> io.vavr.collection.Iterator<io.vavr.Tuple2<T,​U>> zipAll​(Iterable<? extends U> that,
                                                                                  T thisElem,
                                                                                  U thatElem)
        Deprecated.
        This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
        Specified by:
        zipAll in interface io.vavr.collection.Iterator<T>
        Specified by:
        zipAll in interface io.vavr.collection.Traversable<T>
      • zipWithIndex

        default CloseableIterator<io.vavr.Tuple2<T,​Integer>> zipWithIndex()
        Specified by:
        zipWithIndex in interface io.vavr.collection.Iterator<T>
        Specified by:
        zipWithIndex in interface io.vavr.collection.Traversable<T>
      • zipWithIndex

        default <U> CloseableIterator<U> zipWithIndex​(BiFunction<? super T,​? super Integer,​? extends U> mapper)
        Specified by:
        zipWithIndex in interface io.vavr.collection.Iterator<T>
        Specified by:
        zipWithIndex in interface io.vavr.collection.Traversable<T>
      • distinct

        default CloseableIterator<T> distinct()
        Specified by:
        distinct in interface io.vavr.collection.Iterator<T>
        Specified by:
        distinct in interface io.vavr.collection.Traversable<T>
      • distinctBy

        default CloseableIterator<T> distinctBy​(Comparator<? super T> comparator)
        Specified by:
        distinctBy in interface io.vavr.collection.Iterator<T>
        Specified by:
        distinctBy in interface io.vavr.collection.Traversable<T>
      • distinctBy

        default <U> CloseableIterator<T> distinctBy​(Function<? super T,​? extends U> keyExtractor)
        Specified by:
        distinctBy in interface io.vavr.collection.Iterator<T>
        Specified by:
        distinctBy in interface io.vavr.collection.Traversable<T>
      • drop

        default CloseableIterator<T> drop​(int n)
        Specified by:
        drop in interface io.vavr.collection.Iterator<T>
        Specified by:
        drop in interface io.vavr.collection.Traversable<T>
      • dropRight

        default CloseableIterator<T> dropRight​(int n)
        Specified by:
        dropRight in interface io.vavr.collection.Iterator<T>
        Specified by:
        dropRight in interface io.vavr.collection.Traversable<T>
      • dropUntil

        default CloseableIterator<T> dropUntil​(Predicate<? super T> predicate)
        Specified by:
        dropUntil in interface io.vavr.collection.Iterator<T>
        Specified by:
        dropUntil in interface io.vavr.collection.Traversable<T>
      • dropWhile

        default CloseableIterator<T> dropWhile​(Predicate<? super T> predicate)
        Specified by:
        dropWhile in interface io.vavr.collection.Iterator<T>
        Specified by:
        dropWhile in interface io.vavr.collection.Traversable<T>
      • filter

        default CloseableIterator<T> filter​(Predicate<? super T> predicate)
        Specified by:
        filter in interface io.vavr.collection.Iterator<T>
        Specified by:
        filter in interface io.vavr.collection.Traversable<T>
      • reject

        default CloseableIterator<T> reject​(Predicate<? super T> predicate)
        Specified by:
        reject in interface io.vavr.collection.Iterator<T>
        Specified by:
        reject in interface io.vavr.collection.Traversable<T>
      • flatMap

        @Deprecated
        default <U> io.vavr.collection.Iterator<U> flatMap​(Function<? super T,​? extends Iterable<? extends U>> mapper)
        Deprecated.
        This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
        Specified by:
        flatMap in interface io.vavr.collection.Iterator<T>
        Specified by:
        flatMap in interface io.vavr.collection.Traversable<T>
      • grouped

        default CloseableIterator<io.vavr.collection.Seq<T>> grouped​(int size)
        Specified by:
        grouped in interface io.vavr.collection.Iterator<T>
        Specified by:
        grouped in interface io.vavr.collection.Traversable<T>
      • init

        default CloseableIterator<T> init()
        Specified by:
        init in interface io.vavr.collection.Iterator<T>
        Specified by:
        init in interface io.vavr.collection.Traversable<T>
      • iterator

        default CloseableIterator<T> iterator()
        Specified by:
        iterator in interface Iterable<T>
        Specified by:
        iterator in interface io.vavr.collection.Iterator<T>
        Specified by:
        iterator in interface io.vavr.collection.Traversable<T>
        Specified by:
        iterator in interface io.vavr.Value<T>
      • map

        default <U> CloseableIterator<U> map​(Function<? super T,​? extends U> mapper)
        Specified by:
        map in interface io.vavr.collection.Iterator<T>
        Specified by:
        map in interface io.vavr.collection.Traversable<T>
        Specified by:
        map in interface io.vavr.Value<T>
      • orElse

        @Deprecated
        default io.vavr.collection.Iterator<T> orElse​(Iterable<? extends T> other)
        Deprecated.
        This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
        Specified by:
        orElse in interface io.vavr.collection.Iterator<T>
        Specified by:
        orElse in interface io.vavr.collection.Traversable<T>
      • orElse

        @Deprecated
        default CloseableIterator<T> orElse​(Supplier<? extends Iterable<? extends T>> supplier)
        Deprecated.
        This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
        Specified by:
        orElse in interface io.vavr.collection.Iterator<T>
        Specified by:
        orElse in interface io.vavr.collection.Traversable<T>
      • peek

        default CloseableIterator<T> peek​(Consumer<? super T> action)
        Specified by:
        peek in interface io.vavr.collection.Iterator<T>
        Specified by:
        peek in interface io.vavr.collection.Traversable<T>
        Specified by:
        peek in interface io.vavr.Value<T>
      • replace

        default CloseableIterator<T> replace​(T currentElement,
                                             T newElement)
        Specified by:
        replace in interface io.vavr.collection.Iterator<T>
        Specified by:
        replace in interface io.vavr.collection.Traversable<T>
      • replaceAll

        default CloseableIterator<T> replaceAll​(T currentElement,
                                                T newElement)
        Specified by:
        replaceAll in interface io.vavr.collection.Iterator<T>
        Specified by:
        replaceAll in interface io.vavr.collection.Traversable<T>
      • retainAll

        default CloseableIterator<T> retainAll​(Iterable<? extends T> elements)
        Specified by:
        retainAll in interface io.vavr.collection.Iterator<T>
        Specified by:
        retainAll in interface io.vavr.collection.Traversable<T>
      • scanLeft

        default <U> CloseableIterator<U> scanLeft​(U zero,
                                                  BiFunction<? super U,​? super T,​? extends U> operation)
        Specified by:
        scanLeft in interface io.vavr.collection.Iterator<T>
        Specified by:
        scanLeft in interface io.vavr.collection.Traversable<T>
      • scanRight

        default <U> CloseableIterator<U> scanRight​(U zero,
                                                   BiFunction<? super T,​? super U,​? extends U> operation)
        Specified by:
        scanRight in interface io.vavr.collection.Iterator<T>
        Specified by:
        scanRight in interface io.vavr.collection.Traversable<T>
      • slideBy

        default CloseableIterator<io.vavr.collection.Seq<T>> slideBy​(Function<? super T,​?> classifier)
        Specified by:
        slideBy in interface io.vavr.collection.Iterator<T>
        Specified by:
        slideBy in interface io.vavr.collection.Traversable<T>
      • sliding

        default CloseableIterator<io.vavr.collection.Seq<T>> sliding​(int size)
        Specified by:
        sliding in interface io.vavr.collection.Iterator<T>
        Specified by:
        sliding in interface io.vavr.collection.Traversable<T>
      • sliding

        default CloseableIterator<io.vavr.collection.Seq<T>> sliding​(int size,
                                                                     int step)
        Specified by:
        sliding in interface io.vavr.collection.Iterator<T>
        Specified by:
        sliding in interface io.vavr.collection.Traversable<T>
      • tail

        default CloseableIterator<T> tail()
        Specified by:
        tail in interface io.vavr.collection.Iterator<T>
        Specified by:
        tail in interface io.vavr.collection.Traversable<T>
      • take

        default CloseableIterator<T> take​(int n)
        Specified by:
        take in interface io.vavr.collection.Iterator<T>
        Specified by:
        take in interface io.vavr.collection.Traversable<T>
      • takeRight

        default CloseableIterator<T> takeRight​(int n)
        Specified by:
        takeRight in interface io.vavr.collection.Iterator<T>
        Specified by:
        takeRight in interface io.vavr.collection.Traversable<T>
      • takeUntil

        default CloseableIterator<T> takeUntil​(Predicate<? super T> predicate)
        Specified by:
        takeUntil in interface io.vavr.collection.Iterator<T>
        Specified by:
        takeUntil in interface io.vavr.collection.Traversable<T>
      • takeWhile

        default CloseableIterator<T> takeWhile​(Predicate<? super T> predicate)
        Specified by:
        takeWhile in interface io.vavr.collection.Iterator<T>
        Specified by:
        takeWhile in interface io.vavr.collection.Traversable<T>