Hi Botp,

On Wed, Jul 2, 2008 at 8:44 PM, Pe, Botp <botp / delmonte-phil.com> wrote:
> From: Rudi Cilibrasi [mailto:cilibrar / gmail.com]
> # Subject: thoughts on a more generic Array#partition function
> # ....
> # puts "\nSpecial (new extension) three-way list split"
> # testpart(a) { |i| i % 3 }
>
> how does it compare to #group_by

It is very similar.  Thank you Botp for calling it to my attention.
And thank you Matz for reading my email.
The differences I can understand are as follows:

1) group_by requires eql? and hash methods defined for return types.
npartition requires Sortable .
2) group_by returns a hash, npartition returns an array of arrays

Now that I see group_by I can see that it is not hard to implement the
general partition function using it as just:
h = a.group_by() { |i| func(i) }
h.keys.sort.map { |k| h[k] }

This is not so bad, but perhaps has a small disadvantage that it
requires eql? and hash methods defined unlike npartition.   But I
cannot figure out a simpler version to get array of array's output.
Best regards,

Rudi

-- 
Git, Hg (Mercurial), and Subversion (svn) hosting over SSH
http://sshcontrol.com/