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

Latest commit

 

History

History
81 lines (56 loc) · 2.44 KB

File metadata and controls

81 lines (56 loc) · 2.44 KB
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

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

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)

Syntax

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

// Usage:
List.compareWith comparer source1 source2

Parameters

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

Return Value

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.

Remarks

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.

Example

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

Platforms

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

Version Information

F# Core Library Versions

Supported in: 4.0, Portable

See Also

Collections.List Module (F#)

Microsoft.FSharp.Collections Namespace (F#)