private static <T, R> Supplier<Stream<R>> mapIndexed(Supplier<Stream<T>> seq, BiFunction<Integer, T, R> function) {
        return () -> {
            Iterator<T> seqIt = seq.get().iterator();
            Iterator<R> it = new Iterator<R>() {
                private int index = 0;

                @Override
                public boolean hasNext() {
                    return seqIt.hasNext();
                }

                @Override
                public R next() {
                    return function.apply(index++, seqIt.next());
                }
            };
            return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, 0), false);
        };
    }
Test scenarios to cover OffsetKeyedTreeMap data structure

orderings (M)
 - ascending
 - descending
 - random
<p>
modification scenarios (P)
 - all insertions (n)
 - all insertions, then all remove (different series proportions n,m)
 - intermixed insertions and remove (different series proportions n,m)
 - all insertions, then apply offset at existing key
 - all insertions, then apply offset at missing key
 - intermixed insertions, remove, apply offset (different series proportions n,m,p)
 - all insertions, then removeAtRange at existing key
 - all insertions, then removeAtRange offset at missing key
 - intermixed insertions, removeAtRange, apply offset (different series proportions n,m,p)
<p>
inspection scenarios (Q)
 - find existing key
 - find missing key
 - find existing key and iterate forward/backward till the end/head
 - find missing key and iterate forward/backward till the end/head
 - random backward-forward iterations
<p>
test/org.jkiss.dbeaver.model.lsm.test/src/org/jkiss/dbeaver/model/lsm/test/OffsetKeyedTreeMapTest.java