:: (a -> a -> Bool) -> [a] -> [[a]] -package:utility-ht

The groupBy function is the non-overloaded version of group. When a supplied relation is not transitive, it is important to remember that equality is checked against the first element in the group, not against the nearest neighbour:
>>> groupBy (\a b -> b - a < 5) [0..19]
[[0,1,2,3,4],[5,6,7,8,9],[10,11,12,13,14],[15,16,17,18,19]]
It's often preferable to use Data.List.NonEmpty.groupBy, which provides type-level guarantees of non-emptiness of inner lists.

Examples

>>> groupBy (/=) [1, 1, 1, 2, 3, 1, 4, 4, 5]
[[1],[1],[1,2,3],[1,4,4,5]]
>>> groupBy (>) [1, 3, 5, 1, 4, 2, 6, 5, 4]
[[1],[3],[5,1,4,2],[6,5,4]]
>>> groupBy (const not) [True, False, True, False, False, False, True]
[[True,False],[True,False,False,False],[True]]
A version of groupBy that does not assume the argument function is transitive. This is used to partition the Diff list into segments that begin and end with matching (Both) text, with and have non-matching (First and Second) text in the middle.
let notBoth1 a b = not (a == 1 || b == 1) in

groupBy' notBoth1 [1,1,2,3,1,1,4,5,6,1]
[[1],[1,2,3,1],[1,4,5,6,1]]

groupBy notBoth1 [1,1,2,3,1,1,4,5,6,1]
[[1],[1,2,3],[1],[1,4,5,6],[1]]
In the first result the list is split anywhere there are two adjacent ones, as desired.
The groupBy function is the non-overloaded version of group.
Classify values by a given comparison function.
> classifyBy (\(x,_) (y,_) -> x == y) [(1,1),(1,2),(2,1),(2,2)]
[[(1,1),(1,2)],[(2,1),(2,2)]]
(cf. classify, classifyOn)
Alternative to groupBy.
groupBy' (\a b -> abs (a - b) <= 1) [1,2,3] = [[1,2,3]]
whereas
groupBy (\a b -> abs (a - b) <= 1) [1,2,3] = [[1,2],[3]]
TODO: Check in ghc 6.12 release if groupBy == groupBy'.
The groupBy function is the non-overloaded version of group. When a supplied relation is not transitive, it is important to remember that equality is checked against the first element in the group, not against the nearest neighbour:
>>> groupBy (\a b -> b - a < 5) [0..19]
[[0,1,2,3,4],[5,6,7,8,9],[10,11,12,13,14],[15,16,17,18,19]]
It's often preferable to use Data.List.NonEmpty.groupBy, which provides type-level guarantees of non-emptiness of inner lists.
Given a list of nodes, and a function that determines whether there is an edge between any two nodes, yields a list of maximal cliques -- sets of nodes such that every node is connected to every other, and such that no other node may be added while maintaining this property.