From: Robert Klemme Date: 2011-07-25T01:57:14+09:00 Subject: Re: Better name for #zip_with On Sun, Jul 24, 2011 at 8:24 AM, Christopher Dicely wrote: > On Mon, Jul 18, 2011 at 10:25 AM, Robert Klemme > wrote: >> Thomas Sawyer wrote in post #1011313: >>> On Jul 17, 10:36pm, John Feminella wrote: >>>> How about #zip_and_map? Notice that: >>>> >>>> > a.zip_with(b) { |c, d| ... } >>>> >>>> is the same as the result of >>>> >>>> > a.zip(b).map { |c, d| ... } >>> >>> Ah, right. `#zip_map` would makes sense then. But per your last post, >>> I think I may override #zip itself. >> >> Not sure whether I find this a good idea.  Reason: #map has overhead of >> creating a new Array with the same length as the input.  That should not >> be the default behavior IMHO. > > So, don't do that; just return an Enumerator that returns the > successive results of applying the given block to the elements that > would be returned by the Enumerator that would be returned by the > non-block form of #zip. What exactly do you mean? #to_enum does not honor a block: irb(main):001:0> a=5.times.to_a => [0, 1, 2, 3, 4] irb(main):002:0> b=a.to_enum(:map) {|x|x*2} => # irb(main):003:0> b.to_a => [0, 1, 2, 3, 4] Did you mean Generator? irb(main):012:0> b=Enumerator.new {|y| a.each {|x| y << x*2}} => #:each> irb(main):013:0> b.to_a => [0, 2, 4, 6, 8] With #zip irb(main):014:0> b=a.dup => [0, 1, 2, 3, 4] irb(main):015:0> i=Enumerator.new {|y| a.zip(b){|m,n| y << m - n} } => #:each> irb(main):016:0> i.to_a => [0, 0, 0, 0, 0] Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/