Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In Haskell, sortBy takes a comparison function:

  sortBy :: (a -> a -> Ordering) -> [a] -> [a]
And Ordering is defined as:

  data Ordering = LT | EQ | GT
If you want to provide a "key" function rather than a comparison function, you can use sortOn:

  sortOn :: Ord b => (a -> b) -> [a] -> [a]
Which is basically just a sortBy with a function that applies the key function and then compares as normal.


And everything is statically typed.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: