Sort tuples in F #

I have a list of tuples representing the coordinates of points. How can I sort them by the first or second value so that I can order my glasses first from left to right and from top to bottom?

+5
source share
3 answers

It looks like you want, for example,

myList |> List.sortBy fst

http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/FSharp.Core/Microsoft.FSharp.Collections.List.html

But tuples support structural equality and comparison, so default sorting (lexicography) can do what you want.

+5
source

Side note:

, , Set . Tetris.

+1
 let sorted = List.sort_by (fun (a,b) -> a,b) myList

Change a, b if you need another way

0
source

All Articles