Get front row seat and watch the development of micro-isv. We make cool product that solves all your problems...

logo

Friends
         
Comparing and thenComparing Haskell's Data.Ord
2009-03-11

Here's a handy Haskell function when working with Data.Ord:

import Data.Ord
thenComparing :: (Ord b) => (a -> a -> Ordering) -> (a -> b) -> a -> a -> Ordering 
thenComparing prev f a b = let x = prev a b in if x /= EQ then x else comparing f a b

It is used like this:

order = comparing foo `thenComparing` bar
res = sortBy order list