tuple.go

v0.2.0
Doc Versions Source
1
// Package collect provides generic collection types, lazy iterators, and
2
// slice helpers.
3
package collect
4
5
// Tuple2 is a generic pair of values.
6
type Tuple2[T1 any, T2 any] struct {
7
	first  T1
8
	second T2
9
}
10
11
// NewTuple2 creates a [Tuple2] holding first and second.
12
func NewTuple2[T1 any, T2 any](first T1, second T2) Tuple2[T1, T2] {
13
	return Tuple2[T1, T2]{first: first, second: second}
14
}
15
16
// First returns the first element of the pair.
17
func (t *Tuple2[T1, T2]) First() T1 { return t.first }
18
19
// Second returns the second element of the pair.
20
func (t *Tuple2[T1, T2]) Second() T2 { return t.second }
21
22
// Values returns both elements of the pair.
23
func (t *Tuple2[T1, T2]) Values() (T1, T2) { return t.first, t.second }
24
25
// Tuple3 is a generic triple of values.
26
type Tuple3[T1 any, T2 any, T3 any] struct {
27
	first  T1
28
	second T2
29
	third  T3
30
}
31
32
// NewTuple3 creates a [Tuple3] holding first, second, and third.
33
func NewTuple3[T1 any, T2 any, T3 any](first T1, second T2, third T3) Tuple3[T1, T2, T3] {
34
	return Tuple3[T1, T2, T3]{first: first, second: second, third: third}
35
}
36
37
// First returns the first element of the triple.
38
func (t *Tuple3[T1, T2, T3]) First() T1 { return t.first }
39
40
// Second returns the second element of the triple.
41
func (t *Tuple3[T1, T2, T3]) Second() T2 { return t.second }
42
43
// Third returns the third element of the triple.
44
func (t *Tuple3[T1, T2, T3]) Third() T3 { return t.third }
45
46
// Values returns all three elements of the triple.
47
func (t *Tuple3[T1, T2, T3]) Values() (T1, T2, T3) { return t.first, t.second, t.third }
48

Source Files