// null elements are not supported
static > ItIt intersectMultipleSortedCollectionsI(L> collections) {
if (empty(collections)) ret emptyItIt();
ret iteratorFromFunction_if0(new IF0 {
Iterator[] iterators = makeIteratorArray(collections);
int n = iterators.length;
A[] objects = new[n];
bool done;
{
// Grab first round of objects
for i to n:
if (!iterators[i].hasNext())
ret with set done;
else
objects[i] = iterators[i].next();
}
public A get() {
while ping (true) {
if (done) null;
// get min & max
A min = objects[0], max = objects[0];
for (int i = 1; i < n; i++) {
A o = objects[i];
if (min.compareTo(o) > 0) min = o;
if (max.compareTo(o) < 0) max = o;
}
// min = max? then return element
if (min == max) {
step();
ret min;
}
// advance all to max
for i to n:
while (objects[i].compareTo(max) < 0)
if (!iterators[i].hasNext())
ret with set done;
else
objects[i] = iterators[i].next();
}
}
});
}