tur/pair
stdlib/pair.tur
typed Pair[A B]: parameterized two-element tuple.
Since: Phase TC1-F
defstruct
Pair
(defstruct Pair [A B])
parameterized two-element tuple with element types A and B.
Since: Phase TC1
defn
pair
(pair [A B])
construct a Pair[A B].
Parameters
| a | first element (type A) | |
| b | second element (type B) |
Returns
A Pair[A B] value.
Example
(pair 1 2) ; => (1, 2)
Since: Phase TC1
defn
pair-fst
(pair-fst [A B])
return the first element of a Pair[A B].
Parameters
| p | Pair[A B] |
Returns
The first element of type A.
Example
(pair-fst (pair 10 20)) ; => 10
Since: Phase TC1
defn
pair-snd
(pair-snd [A B])
return the second element of a Pair[A B].
Parameters
| p | Pair[A B] |
Returns
The second element of type B.
Example
(pair-snd (pair 10 20)) ; => 20
Since: Phase TC1
defn
pair-free
(pair-free [A B])
compatibility no-op for Pair[A B] values.
Parameters
| p | Pair[A B] |
Example
(pair-free my-pair)
Since: Phase TC1
defmacro
pair-eq?
(pair-eq? [p1 p2 fst-cmp snd-cmp])
compare two Pair[A B] values element-wise.
Parameters
| p1 | first Pair[A B] | |
| p2 | second Pair[A B] | |
| fst-cmp | comparator for first element fn [a :int b :int] :bool | |
| snd-cmp | comparator for second element fn [a :int b :int] :bool |
Returns
true if both first and second elements are equal under their comparators.
Example
(pair-eq? (pair 1 2) (pair 1 2) (fn [a b] (= a b)) (fn [a b] (= a b))) ; => true
Since: Phase TC1
defn
pair-eq-carrier?
(pair-eq-carrier? [p1 :int p2 :int fst-cmp snd-cmp])
legacy carrier-ABI helper used inside Pair's Eq instance.
definstance
Eq[Pair]
(definstance Eq [Pair])
element-wise equality using each component's Eq instance.