static L joinIntRangesWithDistanceLessThan(L l, int threshold) { new L out; for i over l: { IntRange r = l.get(i); if (i == 0 || r.start-last(out).end >= threshold) out.add(r); else setLast(out, intRange(last(out).start, r.end)); } ret out; }