tuple

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package tuple provides simple types for combining values.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pair

type Pair[T1, T2 any] struct {
	// contains filtered or unexported fields
}

Pair is a tuple combining two values.

func PairOf

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

PairOf creates a new Pair from the given values.

func (Pair[T1, T2]) First

func (p Pair[T1, T2]) First() T1

First returns the first value of the pair.

Example
package main

import (
	"fmt"

	"github.com/KrischanCS/go-toolbox/tuple"
)

func main() {
	p := tuple.PairOf(1, "b")

	first := p.First()
	fmt.Println(first)

}
Output:

1

func (Pair[T1, T2]) Second

func (p Pair[T1, T2]) Second() T2

Second returns the second value of the pair.

Example
package main

import (
	"fmt"

	"github.com/KrischanCS/go-toolbox/tuple"
)

func main() {
	p := tuple.PairOf(1, "b")

	second := p.Second()

	fmt.Println(second)

}
Output:

b

func (Pair[T1, T2]) String

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

String returns a string representation of the pair in the format:

(Pair[{{type1}}, {{type2}}]: [{{first}}; {{second}}])
Example
package main

import (
	"fmt"

	"github.com/KrischanCS/go-toolbox/tuple"
)

func main() {
	p := tuple.PairOf(1, "b")

	fmt.Println(p.String())

}
Output:

(Pair[int, string]: [1; b])

func (Pair[T1, T2]) Unpack

func (p Pair[T1, T2]) Unpack() (T1, T2)

Unpack returns the values of the pair.

Example
package main

import (
	"fmt"

	"github.com/KrischanCS/go-toolbox/tuple"
)

func main() {
	p := tuple.PairOf(1, "b")

	first, second := p.Unpack()

	fmt.Println(first)
	fmt.Println(second)

}
Output:

1
b

type Triple

type Triple[T1, T2, T3 any] struct {
	// contains filtered or unexported fields
}

Triple is a tuple combining three values.

func TripleOf

func TripleOf[T1, T2, T3 any](first T1, second T2, third T3) Triple[T1, T2, T3]

TripleOf creates a new Triple from the given values.

func (Triple[T1, T2, T3]) First

func (t Triple[T1, T2, T3]) First() T1

First returns the first value of the triple.

Example
package main

import (
	"fmt"

	"github.com/KrischanCS/go-toolbox/tuple"
)

func main() {
	t := tuple.TripleOf(1, "b", 6.28)

	first := t.First()
	fmt.Println(first)

}
Output:

1

func (Triple[T1, T2, T3]) Second

func (t Triple[T1, T2, T3]) Second() T2

Second returns the second value of the triple.

Example
package main

import (
	"fmt"

	"github.com/KrischanCS/go-toolbox/tuple"
)

func main() {
	t := tuple.TripleOf(1, "b", 6.28)

	second := t.Second()
	fmt.Println(second)

}
Output:

b

func (Triple[T1, T2, T3]) String

func (t Triple[T1, T2, T3]) String() string

String returns a string representation of the triple in the format:

(Triple[{{type1}}, {{type2}}, {{type3}}]: [{{first}}; {{second}}; {{third}}])
Example
package main

import (
	"fmt"

	"github.com/KrischanCS/go-toolbox/tuple"
)

func main() {
	t := tuple.TripleOf(1, "b", 6.28)

	fmt.Println(t.String())

}
Output:

(Triple[int, string, float64]: [1; b; 6.28])

func (Triple[T1, T2, T3]) Third

func (t Triple[T1, T2, T3]) Third() T3

Third returns the third value of the triple.

Example
package main

import (
	"fmt"

	"github.com/KrischanCS/go-toolbox/tuple"
)

func main() {
	t := tuple.TripleOf(1, "b", 6.28)

	third := t.Third()
	fmt.Println(third)

}
Output:

6.28

func (Triple[T1, T2, T3]) Unpack

func (t Triple[T1, T2, T3]) Unpack() (T1, T2, T3)

Unpack returns the values of the triple.

Example
package main

import (
	"fmt"

	"github.com/KrischanCS/go-toolbox/tuple"
)

func main() {
	t := tuple.TripleOf(1, "b", 6.28)

	first, second, third := t.Unpack()

	fmt.Println(first)
	fmt.Println(second)
	fmt.Println(third)

}
Output:

1
b
6.28

Jump to

Keyboard shortcuts

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