Issue #4539 has been updated by Jeremy Voorhis.


I think it's worth having Enumerable#zip_with as a new public method. zip_with is the generalization of zip (you can define zip = zipWIth (,) in Haskell). Because zip_with can be implemented directly via inject, it's possible to provide an implementation with a lower complexity than zip composed with map. With respect to the comment about a method ending in a preposition, the Haskell standard provides a good precedent, and a worthy addition to the collection of languages that influenced Ruby.
----------------------------------------
Feature #4539: Array#zip_with
http://redmine.ruby-lang.org/issues/4539

Author: Michael Kohl
Status: Assigned
Priority: Normal
Assignee: Yukihiro Matsumoto
Category: core
Target version: 


Inspired by Haskell's ((|zipWith|)) function, I hacked on together for 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?


-- 
http://redmine.ruby-lang.org