| title | List.compareWith<'T> Function (F#) |
|---|---|
| description | List.compareWith<'T> Function (F#) |
| keywords | visual f#, f#, functional programming |
| author | liboz |
| manager | danielfe |
| ms.date | 07/05/2016 |
| ms.topic | language-reference |
| ms.prod | visual-studio-dev14 |
| ms.technology | devlang-fsharp |
| ms.assetid | 4e128d48-49cb-4985-8b2d-7fcb3ff19721 |
Compares two lists using the given comparison function, element by element.
Namespace/Module Path: Microsoft.FSharp.Collections.List
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
List.compareWith : ('T -> 'T -> int) -> 'T list -> 'T list -> int
// Usage:
List.compareWith comparer source1 source2comparer Type: 'T -> 'T ->int
A function that takes an element from each of the two source lists and returns an int. If it evaluates to a non-zero value, iteration is stopped and that value is returned.
source1 Type: 'T list
The first input list.
source2 Type: 'T list
The second input list.
Returns the first non-zero result from the comparison function. If the first list has a larger element, the return value is always positive. If the second list has a larger element, the return value is always negative. When the elements are equal in the two lists, 1 is returned if the first list is longer, 0 is returned if they are equal in length, and -1 is returned when the second list is longer.
This function is named CompareWith in compiled assemblies. If you are accessing the function from a .NET language other than F#, or through reflection, use this name.
The following example demonstrates the use of List.compareWith to compare two sequences using a custom comparison function.
[!code-fsharpMain]
Output
List1 is less than List2.
42
Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2
F# Core Library Versions
Supported in: 4.0, Portable