Two small requests:
1. A new method, Array.combine (needs a better name for general use).
It takes entries from two (or many) arrays and combines them.
(like a combination of Array.zip, fetch, and map)
For my use, I needed multiplication, but a block would be more general.
a = [1,2,3]
b = [1,3,5]
a.combine(b) => [1,6,15]
Or with a block:
a.combine(b) {|x,y| x*y}
The new method would replace this sequence:
a.zip(b).map {|e| e[0]*e[1]}
or
a.zip(b,c,d).map {|e| e.inject(1) {|prod, n| prod*n} }
2. A block initializer for Array.new, like that for Hash.new.
Good for self-initializing a table of recurrence relations.
a = Array.new() {|self, i| 2*self[i-1] - self[i-2]}
a[0] = 1 # define the first two ...
a[1] = x
a[2] => 2x-1 # the rest are derived on the fly as needed
a[3] => ...
Hopefully, I'm not blind and haven't missed some obvious use
of the existing methods. My apologies if that's the case.
Whatever... just some thoughts. Are they worth adding?
Thanks!