sclass AllOnAll implements Producer> { new L aList; new L bList; LPair todo = new LinkedList; LPair todo2 = new LinkedList; void addA(A a) { newA(a); } void addAIfNotNull(A a) { if (a != null) newA(a); } synchronized void newA(A a) { add(aList, a); addPair(todo, intRange_last(aList), intRange(0, l(bList))); } synchronized void newAs(Iterable l) { fOr (A a : l) newA(a); } void addB(B b) { newB(b); } void addBIfNotNull(B b) { if (b != null) newB(b); } synchronized void newB(B b) { add(bList, b); addPair(todo, intRange(0, l(aList)), intRange_last(bList)); } synchronized void newBs(Iterable l) { fOr (B b : l) newB(b); } public synchronized Pair next() { while (empty(todo2)) { if (empty(todo)) null; Pair p = popFirst(todo); addAll(todo2, outerProduct_pairs(subList(aList, p.a), subList(bList, p.b))); } ret popFirst(todo2); } synchronized L cloneBList() { ret clonedList(bList); } L getAs() { ret aList; } L getBs() { ret bList; } }