| title | List.sortWith<'T> Function (F#) |
|---|---|
| description | List.sortWith<'T> Function (F#) |
| keywords | visual f#, f#, functional programming |
| author | dend |
| manager | danielfe |
| ms.date | 05/16/2016 |
| ms.topic | language-reference |
| ms.prod | visual-studio-dev14 |
| ms.technology | devlang-fsharp |
| ms.assetid | 25abd618-0568-420a-bf8f-851619a4af04 |
Sorts the given list using the given comparison function.
Namespace/Module Path: Microsoft.FSharp.Collections.List
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
List.sortWith : ('T -> 'T -> int) -> 'T list -> 'T list
// Usage:
List.sortWith comparer listcomparer Type: 'T -> 'T ->int
The function to compare the list elements. The function should return -1, 0, or +1 based on the following table:
| Return | If |
|---|---|
| -1 | The first argument should precede the second argument |
| +1 | The first argument should follow the second argument |
| 0 | The first argument is equal (for purpose of sorting) to the second argument and would also be equal to any other argument that is equal to the second. |
list Type: 'Tlist
The input list.
The sorted list.
This is a stable sort, that is, the original order of equal elements is preserved.
This function is named SortWith in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.
[!code-fsharpMain]
Output
Before sorting:
["<>"; "&"; "&&"; "&&&"; "<"; ">"; "|"; "||"; "|||"]
After sorting:
["&"; "|"; "<"; ">"; "&&"; "||"; "<>"; "&&&"; "|||"]
Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2
F# Core Library Versions
Supported in: 2.0, 4.0, Portable