code: public static <E> Iterator<E> indexIterator(IntPredicate hasNext,
                                                IntFunction<E> next) {
      Objects.requireNonNull(hasNext, "hasNext");
      Objects.requireNonNull(next, "next");
  
      class IndexIterator extends BaseIterator<E> {
        private int index;
  
        @Override
        public boolean hasNext() {
          return hasNext.test(index);
        }
  
        @Override
        protected E nextElement() {
          return next.apply(index++);
        }
      }
  
      return new IndexIterator();
    }
docs: Creates an {@link java.util.Iterator} checked has an internal count of how many times it has been called.
  The current index1 is passed to the lambda expressions.
  
  @param hasNext used to implement {@link java.util.Iterator#hasNext()}
  @param next used to implement {@link java.util.Iterator#next()}
  @param <E> the generic type
  @return a new instance