[Issue 13936] groupBy must be redone

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jan 4 23:54:53 PST 2015


https://issues.dlang.org/show_bug.cgi?id=13936

--- Comment #1 from Andrei Alexandrescu <andrei at erdani.com> ---
Sorry, pressed Enter too soon.

The implementation of groupBy in
https://github.com/D-Programming-Language/phobos/pull/2654 must be redone from
the ground up.

The main use case for groupBy is to iterate each element in each group and do
something. That pattern must be supported with no or minimum overhead.
Currently, groupBy iterates the same range twice - once inside each group, and
once again to find the next group in the range of ranges.

One detail - this:

    in
    {
        import core.exception : RangeError;
        if (r.empty) throw new RangeError();
    }

seems superfluous seeing as r itself has whatever protection mechanism in its
own implementation. Just defer to it; add an assert() at the maximum.

--


More information about the Digitalmars-d-bugs mailing list