[WORK] groupBy is in! Next: aggregate

Olivier Grant via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 25 15:54:10 PST 2015


> We already have partition() functions that actually partition a 
> range into two subranges, so adding partitionBy with a 
> different meaning may be confusing. -- Andrei

In ruby, the closest to D's currently-named groupBy method is a 
set of three methods:

slice_before
slice_after
slice_when

http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-slice_when

Your example in ruby would be:

2.2.0 > [293, 453, 600, 929, 339, 812, 222, 680, 529, 
768].slice_when { |x,y| x & 1 != y & 1 }.to_a
=> [[293, 453], [600], [929, 339], [812, 222, 680], [529], [768]]

O.


More information about the Digitalmars-d mailing list