How to order a LIST in F #

General Question F # n00b. How to sort a LIST data structure?

Edit: Sorry, my data structure is actually a list.

Perhaps I should add my code, since just using ".sort" didn't work:

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 Field, constructor, or member of 'sortBy' not defined

pah, what a pain. I am trying this now:

|> List.ofSeq |> List.sortBy

But I get this:

1 . (Security * RoleContributor * RoleContributor * * * * Contributor * SupportingUploadedFile * LargeText) list → 'a, (' b → 'c) → ' b list → 'b list ' (Security * RoleContributor * RoleContributor * * * * * SupportingUploadedFile * LargeText) list ' ' 'a → ' b '

+3
3

Seq.sortBy .

, , .

: : List.sortBy

MSDN:

let sortedList2 = List.sortBy (fun elem -> abs elem) [1; 4; 8; -2; 5]
printfn "%A" sortedList2

2:

, . , .

+5

, Seq.sortBy - . FLinq , ( <@ .. @>), SQL-:

let getDataFromDb (db: MyDB) Id = 
  <@ seq { big honking database/FLinq query 
             yield  (sec, pm, sr, trade, tradeRec, i, pm_firm, files, lt)
     |> Seq.sortBy (fun (_, _, _, _, _, i, _, _, _) -> i) @>
  |> List.ofSeq 

, , , , , key, (sec, pm, ..., lt), :

 |> Seq.sortBy (fun (k, _) -> k)

( LINQ to Entities, , LINQ to SQL).

+3

Using:

Query.query <@ ... @>
|> List.sortBy (fun (sec, _, _, _, _, _, _, _, _) -> sec)

Note that using tuples with so many elements in F # is very bad. Use something more structured as a record type to give names to fields and avoid confusion.

+2
source

Source: https://habr.com/ru/post/1777755/


All Articles