[
https://issues.apache.org/jira/browse/COLLECTIONS-858?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Alexey Pelykh updated COLLECTIONS-858:
--------------------------------------
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+.
[https://github.com/apache/commons-collections/pull/509]
was:
It seems there's no Iterator that would implement the same thing as Python's
itertools.product (quite literally a nested for loop).
https://github.com/apache/commons-collections/pull/509
> CartesianProductIterator
> ------------------------
>
> Key: COLLECTIONS-858
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-858
> Project: Commons Collections
> Issue Type: New Feature
> Components: Iterator
> Reporter: Alexey Pelykh
> Priority: Trivial
>
> 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+.
> [https://github.com/apache/commons-collections/pull/509]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)