groupBy-0.1.0.0: Replacement definition of Data.List.GroupBy

Copyright(c) Donnacha Oisín Kidney 2018
LicenseMIT
Maintainermail@doisinkidney.com
Stabilityexperimental
Portabilityportable
Safe HaskellTrustworthy
LanguageHaskell2010

Data.List.GroupBy

Description

This module provides an alternative definition for groupBy which does not require a transitive equivalence predicate.

Synopsis

Documentation

groupBy :: (a -> a -> Bool) -> [a] -> [[a]] Source #

Groups adjacent elements according to some relation. The relation can be an equivalence:

>>> groupBy (==) "aaabcccdda"
["aaa","b","ccc","dd","a"]
>>> groupBy (==) []
[]

However, it need not be. The function compares adjacent elements only, so it can be used to find increasing subsequences:

>>> groupBy (<=) [1,2,2,3,1,2,0,4,5,2]
[[1,2,2,3],[1,2],[0,4,5],[2]]

It is fully lazy:

>>> head (groupBy (==) (1:2:undefined))
[1]
>>> (head . head) (groupBy undefined (1:undefined))
1
>>> (head . head . tail) (groupBy (==) (1:2:undefined))
2
xs === concat (groupBy (applyFun2 p) xs)
all (not . null) (groupBy (applyFun2 p) xs)

group :: Eq a => [a] -> [[a]] Source #

Groups adjacent equal elements.

>>> group "aaabcccdda"
["aaa","b","ccc","dd","a"]