@@ -0,0 +1,24 @@
1+module Data.List.Group
2+
3+||| The groupBy function returns a list of lists such that the concatenation
4+||| of the list is equal to the argument, and each sublist contains only
5+||| elements that are equal according to the user-supplied predicate.
6+|||
7+||| ```idris example
8+||| groupBy (==) [1, 1, 2, 3, 3]
9+||| ```
10+|||
11+groupBy : (a -> a -> Bool) -> List a -> List (List a)
12+groupBy _ [] = []
13+groupBy p list@(x :: xs) =
14+ let (ys, zs) = span (p x) xs in
15+ (x :: ys) :: groupBy p (assert_smaller list zs)
16+
17+||| The group function is a special case of groupBy.
18+|||
19+||| ```idris example
20+||| group [1, 1, 2, 3, 3]
21+||| ```
22+|||
23+group : Eq a => List a -> List (List a)
24+group = groupBy (==)