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.

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]]
groupBy operates like group, but uses the provided equality predicate instead of ==.
The groupBy function is the non-overloaded version of group.
The groupBy function is the non-overloaded version of group.
O(n) Group characters in a string according to a predicate.
The groupBy function is the non-overloaded version of group.
O(n) Split a vector into a list of slices, using a predicate function. The concatenation of this list of slices is equal to the argument vector, and each slice contains only equal elements, as determined by the equality predicate function. Does not fuse.
>>> import qualified Data.Vector as V

>>> import           Data.Char (isUpper)

>>> V.groupBy (\a b -> isUpper a == isUpper b) (V.fromList "Mississippi River")
["M","ississippi ","R","iver"]
See also groupBy, group.
O(n) Split a vector into a list of slices. The concatenation of this list of slices is equal to the argument vector, and each slice contains only equal elements, as determined by the equality predicate function.
>>> import qualified Data.Vector.Strict as V

>>> import           Data.Char (isUpper)

>>> V.groupBy (\a b -> isUpper a == isUpper b) (V.fromList "Mississippi River")
["M","ississippi ","R","iver"]
See also groupBy.
O(n) Split a vector into a list of slices, using a predicate function. The concatenation of this list of slices is equal to the argument vector, and each slice contains only equal elements, as determined by the equality predicate function. Does not fuse.
>>> import qualified Data.Vector.Primitive as VP

>>> import           Data.Char (isUpper)

>>> VP.groupBy (\a b -> isUpper a == isUpper b) (VP.fromList "Mississippi River")
["M","ississippi ","R","iver"]
See also groupBy, group.
O(n) Split a vector into a list of slices, using a predicate function. The concatenation of this list of slices is equal to the argument vector, and each slice contains only equal elements, as determined by the equality predicate function. Does not fuse.
>>> import qualified Data.Vector.Storable as VS

>>> import           Data.Char (isUpper)

>>> VS.groupBy (\a b -> isUpper a == isUpper b) (VS.fromList "Mississippi River")
["M","ississippi ","R","iver"]
See also groupBy, group.
O(n) Split a vector into a list of slices, using a predicate function. The concatenation of this list of slices is equal to the argument vector, and each slice contains only equal elements, as determined by the equality predicate function. Does not fuse.
>>> import qualified Data.Vector.Unboxed as VU

>>> import           Data.Char (isUpper)

>>> VU.groupBy (\a b -> isUpper a == isUpper b) (VU.fromList "Mississippi River")
["M","ississippi ","R","iver"]
See also groupBy, group.
Grouping input according to an equality function. Subject to fusion Since 0.3.0
This function compares adjacent elements of a list. If two adjacent elements satisfy a relation then they are put into the same sublist. Example:
>>> groupBy (<) "abcdebcdef"
["abcde","bcdef"]
In contrast to that groupBy compares the head of each sublist with each candidate for this sublist. This yields
>>> List.groupBy (<) "abcdebcdef"
["abcdebcdef"]
The second b is compared with the leading a. Thus it is put into the same sublist as a. The sublists are never empty. Thus the more precise result type would be [(a,[a])].
Perform a Fold while grouping the data according to a specified group projection function. Returns the folded result grouped as a map keyed by the group.
Groups elements using results of the given function as keys.
>>> groupBy even [1..6] :: HashMap Bool (NonEmpty Int)
fromList [(False,5 :| [3,1]),(True,6 :| [4,2])]
Group elements of a stream in accordance with the supplied comparison.
>>> S.print $ mapped S.toList $ S.groupBy (>=) $ each [1,2,3,1,2,3,4,3,2,4,5,6,7,6,5]
[1]
[2]
[3,1,2,3]
[4,3,2,4]
[5]
[6]
[7,6,5]
The groupBy function is the non-overloaded version of group.
group takes a sequence and returns a list of sequences such that the concatenation of the result is equal to the argument. Each subsequence in the result contains only equal elements, using the supplied equality test.
> groupBy (==) Mississippi
[M,"i","ss","i","ss","i","pp","i"]
Improper lens that splits after the first group of matching bytes, as defined by the given equality predicate
The groupBy function is a generalized version of group.
The groupBy function is a generalized version of group.
Generic version of group.
O(n) Group characters in a string according to a predicate.