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)) => 'a
second
RESCRIPT
let second: (('a, 'b)) => 'b
ignore
RESCRIPT
let ignore: ('a, 'b) => unit
ignore(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,
) => bool
equal(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,
) => float
compare(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