Documentation
¶
Overview ¶
Package tuple provides extremely simple generic tuple types and utility functions for creating tuples.
Example ¶
package main
import (
"fmt"
"github.com/goaux/tuple"
)
// GetXY is an example function returning a pair of values.
func GetXY() (x, y int) {
return 12, 34
}
// PrintXY is an example function accepting a string and a pair of ints.
func PrintXY(tag string, x, y int) {
fmt.Printf("%s: X=%d Y=%d\n", tag, x, y)
}
// PrintXYPair is an example function wraps PrintXY with accepting a string and a Pair[int, int].
func PrintXYPair(tag string, xy tuple.Pair[int, int]) {
PrintXY(tag, xy.First, xy.Second)
}
func main() {
// Cannot write PrintXY("here", GetXY()) directly.
x, y := GetXY()
PrintXY("here", x, y)
// Using tuple eliminates the need for intermediate variables.
PrintXYPair("here", tuple.MakePair(GetXY()))
}
Output: here: X=12 Y=34 here: X=12 Y=34
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pair ¶
type Pair[T0, T1 any] struct { First T0 Second T1 }
Pair is a generic type for a pair of values.
type Quadruple ¶
type Quadruple[T0, T1, T2, T3 any] struct { First T0 Second T1 Third T2 Fourth T3 }
Quadruple is a generic type for a quadruple of values.
func MakeQuadruple ¶
func MakeQuadruple[T0, T1, T2, T3 any](first T0, second T1, third T2, fourth T3) Quadruple[T0, T1, T2, T3]
MakeQuadruple returns a new Quadruple with the given values.
func NewQuadruple ¶
func NewQuadruple[T0, T1, T2, T3 any](first T0, second T1, third T2, fourth T3) *Quadruple[T0, T1, T2, T3]
NewQuadruple returns a pointer to a new Quadruple with the given values.
type Quintuple ¶
type Quintuple[T0, T1, T2, T3, T4 any] struct { First T0 Second T1 Third T2 Fourth T3 Fifth T4 }
Quintuple is a generic type for a quintuple of values.
func MakeQuintuple ¶
func MakeQuintuple[T0, T1, T2, T3, T4 any](first T0, second T1, third T2, fourth T3, fifth T4) Quintuple[T0, T1, T2, T3, T4]
MakeQuintuple returns a new Quintuple with the given values.
func NewQuintuple ¶
func NewQuintuple[T0, T1, T2, T3, T4 any](first T0, second T1, third T2, fourth T3, fifth T4) *Quintuple[T0, T1, T2, T3, T4]
NewQuintuple returns a pointer to a new Quintuple with the given values.
type Triple ¶
type Triple[T0, T1, T2 any] struct { First T0 Second T1 Third T2 }
Triple is a generic type for a triple of values.
func MakeTriple ¶
MakeTriple returns a new Triple with the given values.