pair

package
v0.0.0-...-89aa834 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package pair provides a generic Pair type for holding two values of any types.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare[T1, T2 cmp.Ordered](p1, p2 Pair[T1, T2]) int

func CompareFirst

func CompareFirst[T1 cmp.Ordered, T2 any](p1, p2 Pair[T1, T2]) int

func CompareSecond

func CompareSecond[T1 any, T2 cmp.Ordered](p1, p2 Pair[T1, T2]) int

Types

type Pair

type Pair[T1, T2 any] struct {
	First  T1
	Second T2
}

Pair represents a tuple of two values of potentially different types.

func New

func New[T1, T2 any](first T1, second T2) Pair[T1, T2]

New creates a new Pair with the given values.

Example
package main

import (
	"fmt"

	"github.com/gopherd/core/container/pair"
)

func main() {
	p := pair.New(10, "ten")
	fmt.Printf("First: %v, Second: %v\n", p.First, p.Second)
}
Output:

First: 10, Second: ten

func (Pair[T1, T2]) String

func (p Pair[T1, T2]) String() string

Jump to

Keyboard shortcuts

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