Sometimes it's more natural to have Array::zip rather than Array#zip. Otherwise first array of list became unnecessary dedicated
cols = first_row.zip(second_row,third_row,fourth_row)
have more natural analog:
cols = Array.zip(first_row,second_row,third_row,fourth_row)
Implementation is obvious:
#4 Updated by Martin Dürst about 3 years ago
The problem becomes even more obvious in the cases where one starts with an array of arrays:
The new way is clear and concise. The old way is a mess. I have definitely met this pattern for zip and product, maybe others. I always wished there had been a better way, but the idea I came up with was something like arrays.zips_many or so. That might work, too, but Array.zip is quite neat, too.
#6 Updated by Ilya Vorontsov about 3 years ago
marcandre (Marc-Andre Lafortune) wrote:
trans (Thomas Sawyer) wrote:
This is probably true of any Array method that take one or more other arrays as argument. Are there other's besides #zip?
I agree and would like
Array.productto be considered as a worthy addition.
Actually! I had such a problem with #product too, but have already forgotten about it.
#8 Updated by Clay Trump about 3 years ago
- File array_product_zip.pdf added
I've had the same issue in the past, so here's a slide for this feature.
On Fri, Jun 1, 2012 at 2:54 AM, prijutme4ty (Ilya Vorontsov) <
Issue #6499 has been updated by prijutme4ty (Ilya Vorontsov).
Actually! I had such a problem with #product too, but have already
forgotten about it.
#10 Updated by Yusuke Endoh about 3 years ago
- Status changed from Assigned to Rejected
Ilya Vorontsov and Clay Trump,
Sorry but this proposal was rejected at the developer meeting (7/21).
Here is a discussion summary:
Matz was NOT positive to this kind of proposals that is for the
sake of symmetric notation.
Matz wants to save those who want Enumerator-version of Array#zip
and product, but it does not require the new-style API.
We should discuss it as another request.
The behavior of Array.zip(*ary) is not trivial if ary == .
The spec candidates are:
- returns an array whose size is the same as the first element, or
- returns an array whose size is the same as the shortest element
If ary == , both do not make sense because neither the first
element or the shortest one exist.
It may be intuitive to return an infinite array: [, , , ...]
Yusuke Endoh email@example.com
#12 Updated by Marc-Andre Lafortune over 2 years ago
I've thought a bit about this, and the proposed
Array.zip basically already exists if all arrays have the same length.
Array.zip([1,2,3], [4,5,6]) == [[1,2,3], [4,5,6]].transpose
Note that the case of
Array.zip() could be debated, but, as explained in https://bugs.ruby-lang.org/issues/6852,
.transpose is the best answer.
Because of this, it seems there is a lesser need for
On the other hand, I am still confident that
Array.product or similar, would be helpful. I hope I won't offend anyone by opening a new request.