Description
The CartesianProductIterator is suitable to enhance a deeply-nested for-loops over a set of collections.
Given
var a = new Arrays.asList('a1', 'a2', 'a3'); var b = new Arrays.asList('b1', 'b2', 'b3'); var c = new Arrays.asList('c1', 'c2', 'c3'); var d = new Arrays.asList('d1', 'd2', 'd3'); var e = new Arrays.asList('e1', 'e2', 'e3'); var f = new Arrays.asList('f1', 'f2', 'f3');
instead of
for (var aElement : a) { for (var bElement : b) { for (var cElement : c) { for (var dElement : d) { for (var eElement : e) { for (var fElement : f) { // ... } } } } } }
it would look like:
var it = new CartesianProductIterator<>(a, b, c, d, e, f); while (it.hasNext()) { var elements = it.next(); }
Extremely useful for nesting levels 10+.
Attachments
Issue Links
- links to