Re: partition_by
From:
Anders Bengtsson <ndrsbngtssn@...>
Date:
2002-11-16 13:13:35 UTC
List:
ruby-core #578
Florian Frank wrote:
> Hi!
>
> (0..9).partition_by { |x| x % 3 }
> ==>{0=>[0, 3, 6, 9], 1=>[1, 4, 7], 2=>[2, 5, 8]}
>
> ["abc","defg","123","a","xyz","mnop"].partition_by { |x| x.size }
> ==>{1=>["a"], 3=>["abc", "123", "xyz"], 4=>["defg", "mnop"]}
>
> ["abc","bcd","abcde","cdef","bc","abcdef"].partition_by { |x| x[0] }
> ==>{99=>["cdef"], 97=>["abc", "abcde", "abcdef"], 98=>["bcd", "bc"]}
>
> What do you think?
We have a method just like that in JRuby, which we use a lot internally.
But we've named it "group_by", inspired by SQL.
/Anders
--
A n d e r s B e n g t s s o n | ndrsbngtssn@yahoo.se
Stockholm, Sweden |
_____________________________________________________
Fj VM pn舐a h虱l pYahoo!s officielle VM-sajt www.yahoo.se/vm2002
H虱l dig ajour med nyheter och resultat, med vinnare och florare...