Issue #4539 has been updated by shevegen (Robert A. Heiler).


Martin added this to the next developer meeting. I have not yet commented on
this issue so I may briefly do so.

matz asked back then between zip_with, or zip with symbol. I think zip_with may
be better than zip with symbol from a use-point of view.

As for zip_with versus map_with as shown by aprescott - I think zip_with may be
better than putting an additional map_* name. I guess you could reason for an
alias either way, but perhaps it would be better to keep it simple and start
only with zip_with, see whether this may be used at all, before considering
map_* changes (as a name; keep in mind that we have other use cases already
with .map, such as .map.with_index(2) and such. This is also another reason
why I think zip_* would be better than a map_* change here. But you could
also reason either way if people don't read docs, and want to use a .map_*
variant instead. :P Either way, I think it would be better to see for
the potential use cases for .zip_with first).

It may also be worthwhile to ask mame for his opinion again too, years later,
to see how/if  any opinions changed/adapted/stayed the same or not in regards
to the feature. :) (Actually, if it is a new method, then any object allocation
situation may not be very important, since it would not effect more general
use cases, e. g. current use of .zip() and such; but I do not know the C
internals so I have no real clue).

----------------------------------------
Feature #4539: Array#zip_with
https://bugs.ruby-lang.org/issues/4539#change-82288

* Author: citizen428 (Michael Kohl)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
Inspired by Haskell's `zipWith` function, I hacked on together for Ruby:

```ruby
[1,2,3].zip_with([6,5,4], :+) #=> [7, 7, 7]
[1,2,3].zip_with([6,5,4]) { |a,b| 3*a+2*b } #=> [15, 16, 17]
```

So far I only have a Ruby version of it:

https://gist.github.com/731702b90757e21cadcb

My questions:

1. Would this method be considered a worthwhile addition to `Array`?

2. I've never hacked on the C side of Ruby (read some parts of the source though) and my C is quite rusty. I'd like to change that, would somebody be willing to help me turn this into a proper patch?





-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>