Documentation
¶
Overview ¶
Package pair provides a simple Pair type to hold two values of potentially different types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare provides an integer representing the relative order of two Pair values. The semantics of the result are the same as for cmp.Compare, but the First fields are compared first, and only if they are equal are the Second fields compared.
This only works when both fields implement the Ordered interface.
func Equal ¶
func Equal[T, U comparable](a, b Pair[T, U]) bool
Equal compares two Pair values for equality. It returns true if the two Pairs have the same First and Second values, and false otherwise.
This only works when both fields implement the comparable interface.
Types ¶
type Ordered ¶
Ordered is an alias for the cmp.Ordered type, which represents any type that implements the standard comparison operators (<, >, <=, >=, ==, !=).
type Pair ¶
type Pair[T, U any] struct { A T B U }
A Pair holds two values of potentially different types.
func (Pair[T, U]) First ¶
func (p Pair[T, U]) First() T
First returns the first value stored in the Pair.
func (Pair[T, U]) Format ¶
Format writes a string representation of the Pair in the format "Pair{<First>,<Second>}" as part of a fmt.*printf call. The format verb is ignored. If the # flag is set, the type parameters are also included in the format "Pair[T,U]{<First>,<Second>}".
func (Pair[T, U]) Second ¶
func (p Pair[T, U]) Second() U
Second returns the second value stored in the Pair.
func (Pair[T, U]) String ¶
String returns a string representation of the Pair in the format "Pair{<First>, <Second>}".