Hoogle Search
Within LTS Haskell 24.4 (ghc-9.10.2)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
sortBy :: ListLike full item => (item -> item -> Ordering) -> full -> fullListLike Data.ListLike.Base Sort function taking a custom comparison function
sortBy :: (a -> a -> Ordering) -> [a] -> [a]basic-prelude BasicPrelude The sortBy function is the non-overloaded version of sort. The argument must be finite. The supplied comparison relation is supposed to be reflexive and antisymmetric, otherwise, e. g., for _ _ -> GT, the ordered list simply does not exist. The relation is also expected to be transitive: if it is not then sortBy might fail to find an ordered permutation, even if it exists.
Examples
>>> sortBy (\(a,_) (b,_) -> compare a b) [(2, "world"), (4, "!"), (1, "Hello")] [(1,"Hello"),(2,"world"),(4,"!")]
sortOn :: Ord b => (a -> b) -> [a] -> [a]basic-prelude BasicPrelude 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. Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input. The argument must be finite.
Examples
>>> sortOn fst [(2, "world"), (4, "!"), (1, "Hello")] [(1,"Hello"),(2,"world"),(4,"!")]
>>> sortOn length ["jim", "creed", "pam", "michael", "dwight", "kevin"] ["jim","pam","creed","kevin","dwight","michael"]
Performance notes
This function minimises the projections performed, by materialising the projections in an intermediate list. For trivial projections, you should prefer using sortBy with comparing, for example:>>> sortBy (comparing fst) [(3, 1), (2, 2), (1, 3)] [(1,3),(2,2),(3,1)]
Or, for the exact same API as sortOn, you can use `sortBy . comparing`:>>> (sortBy . comparing) fst [(3, 1), (2, 2), (1, 3)] [(1,3),(2,2),(3,1)]
sortWith :: (Ord a, IsSequence c) => (Element c -> a) -> c -> cclassy-prelude ClassyPrelude Sort elements using the user supplied function to project something out of each element. Inspired by http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-Exts.html#v:sortWith.
sortQuantVars :: [Var] -> [Var]ghc-lib-parser GHC.Core.Make Sort the variables, putting type and covars first, in scoped order, and then other Ids It is a deterministic sort, meaning it doesn't look at the values of Uniques. For explanation why it's important See Note [Unique Determinism] in GHC.Types.Unique.
sORTKind_maybe :: Kind -> Maybe (TypeOrConstraint, Type)ghc-lib-parser GHC.Core.Type No documentation available.
sortLocatedA :: HasLoc (EpAnn a) => [GenLocated (EpAnn a) e] -> [GenLocated (EpAnn a) e]ghc-lib-parser GHC.Parser.Annotation No documentation available.
sortAvails :: Avails -> DetOrdAvailsghc-lib-parser GHC.Types.Avail sortLocated :: [Located a] -> [Located a]ghc-lib-parser GHC.Types.SrcLoc No documentation available.
sortRealLocated :: [RealLocated a] -> [RealLocated a]ghc-lib-parser GHC.Types.SrcLoc No documentation available.