Like Gustavo implied, if it's numeric, you can negate it to reverse its order in sorting. That's what the unary operator ~-
is for.
Your peculiar choice of data, that is tuples of 'something * int
, let me suspect that you are counting the number of certain occurences, and for that Seq.countBy
may help (sorry, no list equivalent).
// Your key, Some data
[ "9232", false
"8585", false
"9232", true
"9232", true ]
|> Seq.countBy fst
|> Seq.sortBy (snd >> (~-))
// val it : seq<string * int> = seq [("9232", 3); ("8585", 1)]
That's sorted by the count (snd
element of the tuple) of the key (fst
element of the tuple) negated.
true
for ascending orfalse
for descending. If not, you'll just have to reverse the list. – Stunk