The
group function takes a list and returns a list of lists
such that the concatenation of the result is equal to the argument.
Moreover, each sublist in the result is non-empty and all elements are
equal to the first one.
group is a special case of
groupBy, which allows the
programmer to supply their own equality test.
It's often preferable to use
Data.List.NonEmpty.group,
which provides type-level guarantees of non-emptiness of inner lists.
Examples
>>> group "Mississippi"
["M","i","ss","i","ss","i","pp","i"]
>>> group [1, 1, 1, 2, 2, 3, 4, 5, 5]
[[1,1,1],[2,2],[3],[4],[5,5]]