I would like to optimize the following code for brevity.
x1.each { |x| x2.each { |y| .... xN.each { |z| yield {}.merge(x).merge(y)...... merge(z) } } }
Suppose x1, x2, ..., xN are Enumerator objects.
- The above is not brief.
- It works with x1, x2 as
Array s, but not as Enumerator s- Since enumerator iterators must be reset for inner loops
I tried this, but to no avail:
[x1, x2, ..., xN].reduce(:product).map { |x| x.reduce :merge }
Any recommendations?
UPDATE
currently being addressed using
[x1, x2, ..., xN].map(:to_a).reduce(:product).map { |x| yield x.flatten.reduce(:merge) }
source share