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 :: (a -> a -> Ordering) -> [a] -> [a]protolude Protolude 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 o => (a -> o) -> [a] -> [a]protolude Protolude.List No documentation available.
sortBy :: (a -> a -> Ordering) -> [a] -> [a]ghc-internal GHC.Internal.Data.List 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]ghc-internal GHC.Internal.Data.List 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)]
sortBy :: (a -> a -> Ordering) -> [a] -> [a]ghc-internal GHC.Internal.Data.OldList 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]ghc-internal GHC.Internal.Data.OldList 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 b => (a -> b) -> [a] -> [a]ghc-internal GHC.Internal.Exts The sortWith function sorts a list of elements using the user supplied function to project something out of each element In general if the user supplied function is expensive to compute then you should probably be using sortOn, as it only needs to compute it once for each element. sortWith, on the other hand must compute the mapping function for every comparison that it performs.
sortAccountNamesByDeclaration :: Journal -> Bool -> [AccountName] -> [AccountName]hledger-lib Hledger.Data.Account Sort account names by the order in which they were declared in the journal, at each level of the account tree (ie within each group of siblings). Undeclared accounts are sorted last and alphabetically. This is hledger's default sort for reports organised by account. The account list is converted to a tree temporarily, adding any missing parents; these can be kept (suitable for a tree-mode report) or removed (suitable for a flat-mode report).
sortAccountTreeByAmount :: NormalSign -> Account -> Accounthledger-lib Hledger.Data.Account Sort each group of siblings in an account tree by inclusive amount, so that the accounts with largest normal balances are listed first. The provided normal balance sign determines whether normal balances are negative or positive, affecting the sort order. Ie, if balances are normally negative, then the most negative balances sort first, and vice versa.
sortRows :: ReportOpts -> Journal -> [MultiBalanceReportRow] -> [MultiBalanceReportRow]hledger-lib Hledger.Reports.MultiBalanceReport Sort the rows by amount or by account declaration order.