
21 Nov
2006
21 Nov
'06
7:36 a.m.
Matthias Fischmann wrote:
sortBy ((. tail . fst) . compare . tail . fst)
this would actually be a nice thing to have in the standard libraries:
sortOn :: (Ord b) => (a -> b) -> [a] -> [a] sortOn f = sortBy $ (.f) . compare . f I think the recommended way is to define
on f g = \x y -> f (g x) (g y) That way, you can do sortBy (compare `on` snd) [(1,2),(2,1)] => [(2,1),(1,2)] -k