Skip to content
Snippets Groups Projects
Commit d9ceb2fb authored by iori tsu's avatar iori tsu Committed by Marge Bot
Browse files

Add documentation for GHC.Exts.sortWith

sortWith has the same type definition as `Data.List.sortOn` (eg: `Ord b => (a -> b) -> [a] -> [a]`).
Nonetheless, they behave differently, sortOn being more efficient.
This merge request add documentation to reflect on this differences
parent c1549069
No related branches found
No related tags found
No related merge requests found
...@@ -149,6 +149,11 @@ the [] = errorWithoutStackTrace "GHC.Exts.the: empty list" ...@@ -149,6 +149,11 @@ the [] = errorWithoutStackTrace "GHC.Exts.the: empty list"
-- | The 'sortWith' function sorts a list of elements using the -- | The 'sortWith' function sorts a list of elements using the
-- user supplied function to project something out of each element -- 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 'Data.List.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.
sortWith :: Ord b => (a -> b) -> [a] -> [a] sortWith :: Ord b => (a -> b) -> [a] -> [a]
sortWith f = sortBy (\x y -> compare (f x) (f y)) sortWith f = sortBy (\x y -> compare (f x) (f y))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment