From: Simon Strandgaard Date: 2004-04-13T07:19:13+09:00 Subject: Re: proposal - zip to do padding On Tue, 13 Apr 2004 07:47:38 +0900, Mark Hubbart wrote: > On Apr 12, 2004, at 5:29 AM, Simon Strandgaard wrote: >> My proposal is about changing the current behavier of 1.9, >> so that it does padding, rather than placing all the >> supplied arguments to the first element only. >> >> The current behavier >> irb(main):001:0> (4..6).zip('a') >> => [[4, "a"], [5, nil], [6, nil]] >> irb(main):002:0> (4..6).zip('a', 'b') >> => [[4, "a", "b"], [5, nil, nil], [6, nil, nil]] >> irb(main):003:0> >> >> Proposed behavier >> irb(main):001:0> (4..6).zip('a') >> => [[4, "a"], [5, "a"], [6, "a"]] >> irb(main):002:0> (4..6).zip('a', 'b') >> => [[4, "a", "b"], [5, "a", "b"], [6, "a", "b"]] >> irb(main):003:0> > > As pointed out by someone else, how should we determine when to pad > with an object, and when to zip? Only zip if the object implements > #to_ary? or #each? or, perhaps, #next? Bommer, in the above example I have passed Strings to zip, which includes Enumerable. I thought about using Enumerable to destinguish between padding elements and normal elements. However Fixnum doesn't include Enumerable, so the example would be: irb(main):001:0> (4..6).zip(666) => [[4, 666], [5, 666], [6, 666]] irb(main):002:0> (4..6).zip(:a, :b) => [[4, :a, :b], [5, :a, :b], [6, :a, :b]] irb(main):003:0> It seems as if the current #zip uses Enumerable. Thats why I thought to continue using Enumerable.. Any ideas to distinguish by other means? > > Perhaps if you would post some code it would clear this up, so that it > would be obvious what the behavior would be. I have posted an example in the other thread http://ruby-talk.org/97006 However it doesn't distinguish by if Enumerable is included, nor uses continuations. Maybe I will clean up the example by means of 'enumerator' ? > Note that I'm not against it; I just want to know how it would work. If > you can get it to work intuitively, then I would be all for it. :) > Great with mental support. Its hard to defend proposals. Its good to hear people open to new ideas. ;-) -- Simon Strandgaard