code: public static <R> CloseableIterator<R> iterator(BaseStream<R, Stream<R>> stream) {
        Iterator<R> iterator = stream.iterator();
        if (iterator instanceof CloseableIterator) {
           return (CloseableIterator<R>) iterator;
        }
        return new StreamToCloseableIterator<>(stream, iterator);
     }
docs: Creates a closeable iterator that when closed will close the underlying stream as well
  @param stream The stream to change into a closeable iterator
  @param <R> The type of the stream
  @return An iterator that when closed will also close the underlying stream