Pair

class Pair<A, B>(val first: A, val second: B) : PairComponents(source)

Stores two typed values with component-wise equality and positional destructuring.

The component references cannot be replaced, but objects stored in them may still be mutable. Construction and copy retain those values without making deep copies. Both component types may be nullable. Guest Pair type parameters are invariant.

val entry = "name" to 42
val (name, value) = entry

Parameters

first

first component value.

second

second component value.

Type Parameters

A

type of the first component.

B

type of the second component.

See also

Constructors

Link copied to clipboard
constructor(first: A, second: B)

Creates a pair containing the supplied values.

Properties

Link copied to clipboard
val first: A

First component, retaining its declared type and value.

Link copied to clipboard
open override val firstComponent: Any?

First component exposed as a nullable Any value.

Link copied to clipboard
val second: B

Second component, retaining its declared type and value.

Link copied to clipboard
open override val secondComponent: Any?

Second component exposed as a nullable Any value.

Functions

Link copied to clipboard
operator fun component1(): A

Returns the first component for positional destructuring.

Link copied to clipboard
operator fun component2(): B

Returns the second component for positional destructuring.

Link copied to clipboard
fun copy(first: A, second: B): Pair<A, B>

Creates a new pair using both explicitly supplied component values.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Compares this pair with another PairComponents value component by component.

Link copied to clipboard
open override fun hashCode(): Int

Combines the hash codes of both component values.

Link copied to clipboard
open override fun toString(): String

Formats the components as (first, second) using their text conversions.