From: Rudi Cilibrasi Date: 2008-07-03T22:16:04+09:00 Subject: Re: thoughts on a more generic Array#partition function On Thu, Jul 3, 2008 at 5:13 AM, Robert Klemme wrote: > 2008/7/3 Rick DeNatale : >> On Thu, Jul 3, 2008 at 12:53 AM, Peņa, Botp wrote: >>> From: Rudi Cilibrasi [mailto:cilibrar@gmail.com] >> Not exactly the same, values doesn't guarantee the desired ordering by key. > > That's easily fixed: > > arbitrary_hash.sort_by {|k,| k}.map {|k,v| v} > > Having said that the #group_by implementation seems the more general > solution (because of less requirements, i.e. keys do not need to > provide <=>). Hi Robert, I have come to agree with your analysis. I think this one-line expression you made is very good: As far as source-code brevity, clarity, and correctness this expression you invented gets high marks because there are no dangling outer variable etc and that is great. But my small problem now is the extra code-block calls during runtime. I guess there is one more code-block call per element in the expression as written compared to npartition. So it is now down to a 1) small efficiency difference (probably npartition is slightly faster but untested) 2) small typing difference (Arrays versus hashses -- can go either way here) 3) less requirements for group_by Thanks for the great input so far. Best regards, Rudi