Differences between group() and chunkBy()
Dennis
dkorpel at gmail.com
Wed Nov 14 12:55:17 UTC 2018
On Wednesday, 14 November 2018 at 12:28:38 UTC, Per Nordlöw wrote:
> Is it because of `group` has a default for the predicate
> whereas `chunkBy` hasn't.
chunkBy splits the range into smaller ranges, group actually
returns tuples of the item and the amount of occurences. Because
in group the condition is fixed to equality, it's redundant to
return a range of [2, 2, 2, 2, 2, 2] for example when you can
simply return a tuple (2, 6).
The example:
group([5, 2, 2, 3, 3]) returns a range containing the tuples
tuple(5, 1), tuple(2, 2), and tuple(3, 2).
Is a bit confusing since tuple(2, 2) looks like it could be a
range of two 2's as well.
More information about the Digitalmars-d-learn
mailing list