Total F# n00b question.
How do I sort a LIST data structure?
Edit: Sorry, my data structure is actually a LIST.
maybe i should add my code since just using “.sort” hasn’t worked:
let getDataFromDb (db: MyDB) Id =
Query.query <@ seq {
big honking database/FLinq query
yield (sec, pm, sr, trade, tradeRec, i, pm_firm, files, lt)
} @> |> List.ofSeq
when I change the last line of code to this:
} @> |> List.ofSeq.sortBy fst
I get the following:
Error 1 The field, constructor or member ‘sortBy’ is not defined
ugh, what a pain. I’m trying this now:
|> List.ofSeq |> List.sortBy
But I’m getting this:
Error 1 Type mismatch. Expecting a (Security * RoleContributor * RoleContributor * SuggestedTrade * SuggestedTradeRecommendation * Idea * RoleContributor * SupportingUploadedFile * LargeText) list -> ‘a but given a (‘b -> ‘c) -> ‘b list -> ‘b list The type ‘(Security * RoleContributor * RoleContributor * SuggestedTrade * SuggestedTradeRecommendation * Idea * RoleContributor * SupportingUploadedFile * LargeText) list’ does not match the type ”a -> ‘b’
Seq.sortBy would do that.
However sorting implies you know the key values of the full sequence at the time of sorting, so by definition you cannot use this on infinite sequences.
Edit:
The equivalent for lists has the same name:
List.sortBy
MSDN example:
Edit 2:
From your new example it seems like you have a list of tuples. Now it depends on what item in the tuple you want to search by.