I'm having trouble creating a lazy iterator that returns a tuple in the same way that a simple nested loop would:
for x in (0..5) {
for y in (0..5) {
for z in (0..5) {
(x, y, z);
}
}
}
It seems quite simple but I've yet to find an iterator that can repeat each item n
times, or multizip items out of lock-step. I've given it a few attempts but they all end up with me creating collections of duplicated indices such as below:
let x_iterator = (0..x_len)
.into_iter()
.flat_map(|x| iter::repeat(x).take(y_len).collect());
// ...
Or some such other combination of nested adapters that force me to eagerly evaluate the inner contents to get the resulting lazy iterator.
- Is there a simpler solution to creating a lazy iterator of these nested values?
- Is there a solution that can create tuples for
n
nested iterators(a, b, .., n)
?