// f : A -> Collection<A> static <A> ItIt<A> mapLike repeatFunctionReturningList_iterator(O f, A input, O... _) { final Set<A> seen = optParOr seen(_, () -> (Set) new HashSet); final Int max = cast optPar max(_); bool plusInput = boolPar plusInput(_); // return original input too? // Make pool of iterators final new LinkedList<Iterator<A>> pool; if (plusInput) pool.add(singletonIterator(input)); else seen.add(input); pool.add(iterator((Iterable<A>) callF(f, input))); ret iteratorFromFunction(new F0<A> { int n = 0; public A get() { if (max != null && n >= max) null; while ping (!empty(pool)) { Iterator<A> it = first(pool); if (!it.hasNext()) continue with removeFirst(pool); // Get entry and check if seen already A entry = it.next(); if (!seen.add(entry)) continue; // found new entry - return and schedule for further analysis Collection<A> newStuff = cast callF(f, entry); if (nempty(newStuff)) pool.add(iterator(newStuff)); ++n; ret entry; } null; } }); }