pair

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 2 Imported by: 0

README

Pair Package

The pair package provides a concrete implementation of a Pair of values. A Pair is a data structure that holds two values of any type.

Usage

To use the pair package, import it into your project:

import (
    ...
    "github.com/arthurcgc/pair"
    ...
)

To create a new pair, use the NewPair function:

p := pair.NewPair(1, 2.0)

To get the first and second values of the pair, use the First and Second methods, respectively:

p := pair.NewPair(1, "hello")
fmt.Println(p.First) // 1
fmt.Println(p.Second) // hello

To get the string representation of the pair, use the String method:

p := pair.NewPair(1, 2.0)
fmt.Println(p.String()) // (1, 2.0)

To check if two pairs are equal, use the Equals function:

p1 := pair.NewPair(1, 2)
p2 := pair.NewPair(1, 2)
fmt.Println(Equals(p1, p2)) // true
p1 := pair.NewPair(1, "hello")
p2 := pair.NewPair(1, "world")
fmt.Println(Equals(p1, p2)) // false
Supported Types

The Pair package supports the following types:

  • int
  • int32
  • int64
  • uint
  • uint32
  • uint64
  • float32
  • float64
  • string
  • bool

I intend to add support for more types in the future.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Overview

pair is a package that defines a generic Pair type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T1, T2 pairType](pair1, pair2 *Pair[T1, T2]) bool

Equal returns true if the two Pairs are equal.

Types

type Pair

type Pair[T1 pairType, T2 pairType | bool] struct {
	First  T1
	Second T2
}

Pair is a generic pair of values.

func New

func New[T1, T2 pairType](p1 T1, p2 T2) *Pair[T1, T2]

New returns a new Pair.

func (*Pair[T1, T2]) String

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

String returns a string representation of the Pair.

Jump to

Keyboard shortcuts

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