Data.Sort (original) (raw)
The Vanilla Sorts
The [sort](Data-Sort.html#v:sort)
function implements a stable sorting algorithm. It is a special case of [sortBy](Data-Sort.html#v:sortBy)
, which allows the programmer to supply their own comparison function.
sortOn :: Ord b => (a -> b) -> [a] -> [a] #
Sort a list by comparing the results of a key function applied to each element. sortOn f
is equivalent to sortBy (comparing f)
, but has the performance advantage of only evaluating f
once for each element in the input list. This is called the decorate-sort-undecorate paradigm, or Schwartzian transform.
Since: 4.8.0.0
Sorting Associations
monoidSortAssocsBy :: Monoid a => (k -> k -> Ordering) -> [(k, a)] -> [(k, a)] Source #
Sort the list of associations, aggregating duplicates with the monoid and ordering the keys with the argument compare function.
groupSortAssocs :: Ord k => (k -> a -> [a] -> b) -> [(k, a)] -> [(k, b)] Source #
Sort the list of associations, aggregating duplicates with the supplied function.
groupSortAssocsBy :: (k -> k -> Ordering) -> (k -> a -> [a] -> b) -> [(k, a)] -> [(k, b)] Source #
Sort the list of associations, aggregating duplicates with the supplied function and ordering the keys with the argument compare function.
Sorting with Monoids
monoidSortOn :: (Monoid a, Ord k) => (a -> k) -> [a] -> [a] Source #
Sort the list, agregating duplicates with the monoid and ordering the elements by the items generated by the argument function.
monoidSortBy :: Monoid a => (a -> a -> Ordering) -> [a] -> [a] Source #
Sort the list, agregating duplicates with the monoid and ordering the keys with the argument compare function.
Unique Sorts
uniqueSortOn :: Ord k => (a -> k) -> [a] -> [a] Source #
Sort the list, discarding duplicates and ordering the elements by the items generated by the argument function.
uniqueSortBy :: (a -> a -> Ordering) -> [a] -> [a] Source #
Sort the list, discarding duplicates and ordering the keys with the argument compare function.
Group Sorting
groupSort :: Ord a => (a -> [a] -> b) -> [a] -> [b] Source #
Sort a list of elements with a stable sort, grouping together the equal elements with the argument grouping function
groupSortOn :: Ord k => (a -> k) -> (k -> a -> [a] -> b) -> [a] -> [b] Source #
Sort a list of elements with a stable sort, using the argumentcompare
function determine the ordering, grouping together the equal elements with the grouping function
groupSortBy :: (a -> a -> Ordering) -> (a -> [a] -> b) -> [a] -> [b] Source #
Sort a list of elements with a stable sort, grouping together the equal elements with the argument grouping function.