I have a list of tuples representing coordinates of points. How can I sort them by the first or second value, so that I could order my points from left to right first and from top to bottom next?
+4
A:
Sounds like you want e.g.
myList |> List.sort_by fst
But tuples support structural equality and comparison, so the default sort (lexicographical) may do what you want.
Brian
2009-04-30 10:29:29
sort_by was later renamed to sortBy
Sergej Andrejev
2009-05-22 07:24:16
A:
let sorted = List.sort_by (fun (a,b) -> a,b) myList
Change the a,b if you need the other way around
Can Erten
2009-04-30 11:16:18