pair

package
v1.20.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package pair provides a generic Pair type for representing pairs of values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pair

type Pair[A any, B any] struct {
	A A
	B B
}

Pair is a pair of values.

Pair is commonly used with iterators for operations like Zip and Enumerate, as well as with Option for Zip and Unzip operations.

Examples

// Create a pair
p := pair.Pair[int, string]{A: 42, B: "hello"}
a, b := p.Split()
fmt.Println(a, b) // Output: 42 hello

// Use with iterators
iter1 := iterator.FromSlice([]int{1, 2, 3})
iter2 := iterator.FromSlice([]string{"a", "b", "c"})
zipped := iterator.Zip(iter1, iter2)
for opt := zipped.Next(); opt.IsSome(); opt = zipped.Next() {
	p := opt.Unwrap()
	fmt.Println(p.A, p.B) // Output: 1 a, 2 b, 3 c
}

func (Pair[A, B]) Split

func (p Pair[A, B]) Split() (A, B)

Split splits the pair into its two components.

Examples

p := pair.Pair[int, string]{A: 42, B: "hello"}
a, b := p.Split()
fmt.Println(a, b) // Output: 42 hello

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL