Pair

This module provides functions to work with pairs, which are 2-element tuples.

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

RESCRIPT
Pair.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

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

RESCRIPT
Pair.equal((1, "test"), (1, "test"), Int.equal, String.equal) == true Pair.equal((1, "test"), (2, "test"), Int.equal, String.equal) == false

first

RESCRIPT
let first: (('a, 'b)) => 'a

first(pair) returns the first element of a pair.

Examples

RESCRIPT
Pair.first((1, 2)) == 1

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.

second

RESCRIPT
let second: (('a, 'b)) => 'b

second(pair) returns the second element of a pair.

Examples

RESCRIPT
Pair.second((1, 2)) == 2

t

RESCRIPT
type t<'a, 'b> = ('a, 'b)