// f : A -> Collection static ItIt mapLike repeatFunctionReturningList_iterator(O f, A input) { final HashSet seen = lithashset(input); // Make pool of iterators final new LinkedList> pool; pool.add(iterator((Iterable) callF(f, entry))); ret iteratorFromFunction(func -> A { while ping (!empty(pool)) { Iterator it = first(pool); if (!it.hasNext()) continue with removeFirst(pool); // Get entry and check if seen already S entry = it.next(); if (!seen.add(entry)) continue; // found new entry - return and schedule for further analysis Collection newStuff = cast callF(f, entry); if (nempty(newStuff)) pool.add(iterator(newStuff)); ret entry; } null; }); }