www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Differences between group() and chunkBy()

reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
Why is there at

https://dlang.org/phobos/std_algorithm_iteration.html

an inconsistency in naming of `group` and chunkBy`?

Is it because of `group` has a default for the predicate whereas 
`chunkBy` hasn't.

Further, why aren't the two merged into a single iteration 
algorithm?
Nov 14 2018
parent Dennis <dkorpel gmail.com> writes:
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.
Nov 14 2018