IterTools.groupby doesn't group nonconsecutive elements together.
When I execute the following code:
my_list = [ ["u",1], ["u",2], ["a",1], ["d", 1], ["a",2],["d",2]]
collect(IterTools.groupby(s->s[1], my_list))
I get as output:
[["u", 1], ["u", 2]]
[["a", 1]]
[["d", 1]]
[["a", 2]]
[["d", 2]]
So it seems that the items with key a and d are not properly grouped together.
Environment: Julia v1.10.9 itertools v1.10.0
This is documented.
Group consecutive values that share the same result of applying
f.
https://github.com/JuliaCollections/IterTools.jl/blob/5eeba86ecb167993cec41d6dfde171946d398b98/src/IterTools.jl#L385
Same behavour as python's
I know some other language/library does it the way you want, but i can't remember which.
I feel like i did a writeup at some point.
SplitApplyCombine.jl's group is at least on such.
I feel like both are valuable.
and having to call sort before groupby seems unnesc.
Maybe we should just have groupby_consective and groupby_nonconsective, and be really explicit.