Seq.sort, pipeline. We can sort collections with Seq.sort. With Seq.ofList, we treat a list as a sequence. Then we can use functions like where and sort in a pipeline.
Here We use "where" to only keep elements containing a lowercase "A." Then we sort them alphabetically, and convert back to a list.
let animals = ["cat"; "bird"; "zebra"; "leopard"; "shark"]
// Act on list as a sequence.// ... Use where to filter our list.// Use Seq.sort to sort the sequence.// Use Seq.toList to convert back to a list.
let sortResult =
|> Seq.where (fun x-> x.Contains "a")
// Print all our results.List.iter (fun (x : string) -> printfn "%A" x) sortResult"cat"
With this language, we have features that are well-suited to advanced sorting. We have lambdas and immutable collections (like lists). We invoke built-in sort methods.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.