[WORK] groupBy is in! Next: aggregate
Russel Winder via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jan 26 02:43:40 PST 2015
On Fri, 2015-01-23 at 10:08 -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
[…]
> #!/usr/bin/rdmd
>
> void main()
> {
> import std.algorithm, std.stdio;
> [293, 453, 600, 929, 339, 812, 222, 680, 529, 768]
> .groupBy!(a => a & 1)
> .writeln;
> }
> ----
>
> [[293, 453], [600], [929, 339], [812, 222, 680], [529], [768]]
>
[…]
I think I must be missing something, for me the result of a groupBy
operation on the above input data should be:
[1:[293, 453, 929, 339, 529], 0:[600, 812, 222, 680, 768]]
i.e. a map with keys being the cases and values being the values that
meet the case. In this example a & 1 asks for cases "lowest bit 0 or 1"
aka "odd or even".
There is nothing wrong with the semantics of the result above, but is
it's name "group by" as understood by the rest of the world?
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder at ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: russel at winder.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
More information about the Digitalmars-d
mailing list