Skip to main content

Pair

A container that holds exactly two values, which may be of different types.

Pair is a simple container that bundles together two values into a single object. The two values can be of the same or different types and are accessed via the 'first' and 'second' members. Pairs are commonly used to return multiple values from functions, store key-value associations, or group related data together. They are particularly useful in algorithms and data structures that need to work with coupled values.

Example


var coordinate = Pair(10, 20)
print("X: ${coordinate.first}")
print("Y: ${coordinate.second}")

Constructors

Pair(const Pair other) -> Pair

Creates a copy of an existing Pair object.

Parameters

  • other: The Pair object to copy.

Pair(const Object first, const Object second) -> Pair

Constructs a pair with the specified first and second elements.

Parameters

  • first: The first element of the pair.
  • second: The second element of the pair.

Members

NameDescription
firstReturns the first element of the pair.
secondReturns the second element of the pair.