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 (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 ¶
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 (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 ¶
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
Click to show internal directories.
Click to hide internal directories.