FSharp.Core


ComparisonIdentity Module

Common notions of value ordering implementing the IComparer interface, for constructing sorted data structures and performing sorting operations.

Functions and values

Function or value Description

FromFunction comparer

Full Usage: FromFunction comparer

Parameters:
    comparer : 'T -> 'T -> int - A function to compare two values.

Returns: IComparer<'T> An object implementing IComparer using the supplied function.

Get an implementation of comparison semantics using the given function.

comparer : 'T -> 'T -> int

A function to compare two values.

Returns: IComparer<'T>

An object implementing IComparer using the supplied function.

Example

Create and use a comparer using the given function:

 let comparer = ComparisonIdentity.FromFunction(fun i1 i2 -> compare (i1%5) (i2%5))

 comparer.Compare(7, 2)
Evaluates to 0because 7 and 2 compare as equal using to the provided function.

NonStructural

Full Usage: NonStructural

Returns: IComparer<^T> An object implementing IComparer using NonStructuralComparison.Compare.
Modifiers: inline
Type parameters: ^T

Get an implementation of comparison semantics using non-structural comparison.

Returns: IComparer<^T>

An object implementing IComparer using NonStructuralComparison.Compare.

Example

Create and use a comparer using structural comparison:

 let comparer = ComparisonIdentity.NonStructural<System.DateTime>

 comparer.Compare(System.DateTime.Now, System.DateTime.Today)
Evaluates to 1.

Structural

Full Usage: Structural

Returns: IComparer<'T> An object implementing IComparer using Operators.compare.
Modifiers: inline
Type parameters: 'T

Get an implementation of comparison semantics using structural comparison.

Returns: IComparer<'T>

An object implementing IComparer using Operators.compare.

Example

Create and use a comparer using structural comparison:

 let compareTuples = ComparisonIdentity.Structural<int * int>

 compareTuples.Compare((1, 4), (1, 5))
Evaluates to -1.