Pair
This module provides functions to work with pairs, which are 2-element tuples.
t
RESCRIPT
type t<'a, 'b> = ('a, 'b)first
RESCRIPT
let first: (('a, 'b)) => 'asecond
RESCRIPT
let second: (('a, 'b)) => 'bignore
RESCRIPT
let ignore: ('a, 'b) => unitignore(pair) ignores the provided pair and returns unit.
This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.
equal
RESCRIPT
let equal: (
('a, 'b),
('c, 'd),
('a, 'c) => bool,
('b, 'd) => bool,
) => boolequal(pair1, pair2, f1, f2) check equality of pair2 and pair2 using f1 for
equality on the first element and f2 for equality on the second element.
Examples
RESCRIPTPair.equal((1, "test"), (1, "test"), Int.equal, String.equal) == true
Pair.equal((1, "test"), (2, "test"), Int.equal, String.equal) == false
compare
RESCRIPT
let compare: (
('a, 'b),
('c, 'd),
('a, 'c) => float,
('b, 'd) => float,
) => floatcompare(pair1, pair2, f1, f2) compares two pairs, using f1 to compare the first element
and f2 to compare the second element. Ordering is based on the first element,
if they are equal, the second element is compared.
Examples
RESCRIPTPair.compare((1, "a"), (1, "a"), Int.compare, String.compare) == Ordering.equal
Pair.compare((1, "a"), (1, "b"), Int.compare, String.compare) == Ordering.less
Pair.compare((2, "a"), (1, "b"), Int.compare, String.compare) == Ordering.greater