views:

185

answers:

2

Hello,

Is there any function in F# similar to LINQ fluent syntax for sorting by multiple expressions:

myList.OrderBy(fun x->x.Something).ThenBy(fun x->x.SomethingElse)

I'd love something like:

myList 
|> Seq.sort_by(fun x->x.Something) 
|> Seq.then_by(fun x->x.SomethingElse)

Thx

+1  A: 

You may find some of the sort algorithms here helpful, as I don't know of a wait in F# to do sorting, besides using the .NET functionality.

http://cs.hubfs.net/forums/thread/3876.aspx

James Black
+11  A: 

Use a tuple as your sort key:

myList |> Seq.sort_by (fun x -> x.Something, x.SomethingElse)
Tim Robinson
Right, tuples sort in lexicographical order, so putting multiple keys in order left-to-right in a tuple does just what is desired.
Brian