void () { Function<Integer, JBIterable<Integer>> traversal = TreeTraversal.INTERLEAVED_DFS.traversal( integer -> { JBIterable<Integer> it = JBIterable.generate(1, INCREMENT).takeWhile(UP_TO(integer + 1)); // 1: no repeat return it; // 2: repeat indefinitely: all seq //return JBIterable.generate(it, Functions.id()).flatten(Functions.id()); // 3: repeat indefinitely: self-cycle //return it.append(JBIterable.generate(integer, Functions.id())); }); JBIterable<Integer> counts = JBIterable.generate(1, INCREMENT).transform(integer -> traversal.fun(1).takeWhile(UP_TO(integer)).size()); // 1: no repeat assertEquals(Arrays.asList(1, 4, 13, 39, 117, 359, 1134, 3686, 12276, 41708), counts.take(10).toList()); // 2: repeat all seq //assertEquals(Arrays.asList(1, 4, 19, 236), counts.take(4).toList()); // 2: repeat self-cycle //assertEquals(Arrays.asList(1, 4, 19, 236), counts.take(4).toList()); }