Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Latest commit

 

History

History
87 lines (57 loc) · 2.32 KB

File metadata and controls

87 lines (57 loc) · 2.32 KB
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

List.sortWith<'T> Function (F#)

Sorts the given list using the given comparison function.

Namespace/Module Path: Microsoft.FSharp.Collections.List

Assembly: FSharp.Core (in FSharp.Core.dll)

Syntax

// Signature:
List.sortWith : ('T -> 'T -> int) -> 'T list -> 'T list

// Usage:
List.sortWith comparer list

Parameters

comparer 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.

Return Value

The sorted list.

Remarks

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.

Example

[!code-fsharpMain]

Output

Before sorting:
["<>"; "&"; "&&"; "&&&"; "<"; ">"; "|"; "||"; "|||"]
After sorting:
["&"; "|"; "<"; ">"; "&&"; "||"; "<>"; "&&&"; "|||"]

Platforms

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Collections.List Module (F#)

Microsoft.FSharp.Collections Namespace (F#)