Comparisons Module
Curried comparison active patterns for use directly in a match expression.
Marked with the auto-open attribute: opening TDesu.FSharp.ActivePatterns (or this module
directly) brings Eq, NEq, Lt, Gt, LtEq, GtEq and Between
into scope unqualified. Auto-open only makes sense here because these names are useless qualified —
nobody wants to write Comparisons.Lt inside a match arm. Each pattern takes its comparand(s)
first and the matched value last, so match x with | Lt 10 -> … reads as "x is less than 10".
They rely only on F#'s built-in structural equality/comparison constraints, so they work for any
comparable type — numbers, strings, DateTime, tuples, comparable records — not just numbers.
Each pattern is [<return: Struct>], so a match arm costs no allocation: a plain partial
active pattern would allocate an FSharpOption every time the arm is evaluated, which for a
one-comparison pattern is the whole cost of the match. The use site is unchanged either way.
Active patterns
| Active pattern |
Description
|
Full Usage:
(|Between|_|) lo hi value
Parameters:
'a
-
Inclusive lower bound.
hi : 'a
-
Inclusive upper bound.
value : 'a
-
The value being matched.
Returns: bool
Modifiers: inline Type parameters: 'a |
Matches when the matched value lies within [lo, hi], inclusive on both ends. If lo is greater than hi the range is empty, so the pattern never matches.
Example
|
Full Usage:
(|Eq|_|) comparand value
Parameters:
'a
-
The value to compare against.
value : 'a
-
The value being matched.
Returns: bool
Modifiers: inline Type parameters: 'a |
Matches when the matched value is structurally equal to comparand.
Example
val describe: x: 'a -> string
val x: 'a
|
Full Usage:
(|GtEq|_|) comparand value
Parameters:
'a
-
The value to compare against.
value : 'a
-
The value being matched.
Returns: bool
Modifiers: inline Type parameters: 'a |
Matches when the matched value is greater than or equal to comparand.
Example
|
Full Usage:
(|Gt|_|) comparand value
Parameters:
'a
-
The value to compare against.
value : 'a
-
The value being matched.
Returns: bool
Modifiers: inline Type parameters: 'a |
Matches when the matched value is strictly greater than comparand.
Example
|
Full Usage:
(|LtEq|_|) comparand value
Parameters:
'a
-
The value to compare against.
value : 'a
-
The value being matched.
Returns: bool
Modifiers: inline Type parameters: 'a |
Matches when the matched value is less than or equal to comparand.
Example
|
Full Usage:
(|Lt|_|) comparand value
Parameters:
'a
-
The value to compare against.
value : 'a
-
The value being matched.
Returns: bool
Modifiers: inline Type parameters: 'a |
Matches when the matched value is strictly less than comparand.
Example
|
Full Usage:
(|NEq|_|) comparand value
Parameters:
'a
-
The value to compare against.
value : 'a
-
The value being matched.
Returns: bool
Modifiers: inline Type parameters: 'a |
Matches when the matched value is not structurally equal to comparand.
Example
|
TDesu.FSharp