4 people like it.

Active pattern for comparison

An active pattern for comparing two objects of the same type and implementing IComparable. Modeled on Standard ML comparison.

1: 
2: 
3: 
4: 
5: 
6: 
/// An active pattern that compares two objects of the same type.
let (|Less|Equal|Greater|) (x, y) =
    let cmp = compare x y
    if cmp < 0 then Less
    elif cmp > 0 then Greater
    else Equal
val x : 'a (requires comparison)
val y : 'a (requires comparison)
val cmp : int
val compare : e1:'T -> e2:'T -> int (requires comparison)

Full name: Microsoft.FSharp.Core.Operators.compare

More information

Link:http://fssnip.net/5y
Posted:13 years ago
Author:petebu
Tags: active pattern , comparison , icomparable