-
Notifications
You must be signed in to change notification settings - Fork 1
/
tuples.go
47 lines (39 loc) · 1.01 KB
/
tuples.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package gofn
type Tuple2[T1, T2 any] struct {
Elem1 T1
Elem2 T2
}
// Unpack unpacks elements of tuple, panic on nil pointer
func (tuple2 *Tuple2[T1, T2]) Unpack() (T1, T2) {
return tuple2.Elem1, tuple2.Elem2
}
type Tuple3[T1, T2, T3 any] struct {
Elem1 T1
Elem2 T2
Elem3 T3
}
// Unpack unpacks elements of tuple, panic on nil pointer
func (tuple3 *Tuple3[T1, T2, T3]) Unpack() (T1, T2, T3) {
return tuple3.Elem1, tuple3.Elem2, tuple3.Elem3
}
type Tuple4[T1, T2, T3, T4 any] struct {
Elem1 T1
Elem2 T2
Elem3 T3
Elem4 T4
}
// Unpack unpacks elements of tuple, panic on nil pointer
func (tuple4 *Tuple4[T1, T2, T3, T4]) Unpack() (T1, T2, T3, T4) {
return tuple4.Elem1, tuple4.Elem2, tuple4.Elem3, tuple4.Elem4
}
type Tuple5[T1, T2, T3, T4, T5 any] struct {
Elem1 T1
Elem2 T2
Elem3 T3
Elem4 T4
Elem5 T5
}
// Unpack unpacks elements of tuple, panic on nil pointer
func (tuple5 *Tuple5[T1, T2, T3, T4, T5]) Unpack() (T1, T2, T3, T4, T5) {
return tuple5.Elem1, tuple5.Elem2, tuple5.Elem3, tuple5.Elem4, tuple5.Elem5
}