Skip to content

Commit 69b6995

Browse files
authored
Change generated code to reuse type parameters constraint (#7)
1 parent c16834e commit 69b6995

File tree

9 files changed

+52
-49
lines changed

9 files changed

+52
-49
lines changed

scripts/gen/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,12 @@ func generateFile(context templateContext, outputFilePath string, tpl *template.
117117
func genTypesDecl(indexes []int) string {
118118
sep := make([]string, len(indexes))
119119
for index, typeIndex := range indexes {
120-
sep[index] = fmt.Sprintf("Ty%d any", typeIndex)
120+
sep[index] = fmt.Sprintf("Ty%d", typeIndex)
121121
}
122122

123+
// Add constraint to last element.
124+
sep[len(indexes)-1] += " any"
125+
123126
return strings.Join(sep, ", ")
124127
}
125128

tuple2.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
// T2 is a tuple type holding 2 generic values.
8-
type T2[Ty1 any, Ty2 any] struct {
8+
type T2[Ty1, Ty2 any] struct {
99
V1 Ty1
1010
V2 Ty2
1111
}
@@ -45,7 +45,7 @@ func (t T2[Ty1, Ty2]) GoString() string {
4545
}
4646

4747
// New2 creates a new tuple holding 2 generic values.
48-
func New2[Ty1 any, Ty2 any](v1 Ty1, v2 Ty2) T2[Ty1, Ty2] {
48+
func New2[Ty1, Ty2 any](v1 Ty1, v2 Ty2) T2[Ty1, Ty2] {
4949
return T2[Ty1, Ty2]{
5050
V1: v1,
5151
V2: v2,
@@ -54,7 +54,7 @@ func New2[Ty1 any, Ty2 any](v1 Ty1, v2 Ty2) T2[Ty1, Ty2] {
5454

5555
// FromArray2 returns a tuple from an array of length 2.
5656
// If any of the values can not be converted to the generic type, an error is returned.
57-
func FromArray2[Ty1 any, Ty2 any](arr [2]any) (T2[Ty1, Ty2], error) {
57+
func FromArray2[Ty1, Ty2 any](arr [2]any) (T2[Ty1, Ty2], error) {
5858
v1, ok := arr[0].(Ty1)
5959
if !ok {
6060
return T2[Ty1, Ty2]{}, fmt.Errorf("value at array index 0 expected to have type %s but has type %T", typeName[Ty1](), arr[0])
@@ -69,13 +69,13 @@ func FromArray2[Ty1 any, Ty2 any](arr [2]any) (T2[Ty1, Ty2], error) {
6969

7070
// FromArray2X returns a tuple from an array of length 2.
7171
// If any of the values can not be converted to the generic type, the function panics.
72-
func FromArray2X[Ty1 any, Ty2 any](arr [2]any) T2[Ty1, Ty2] {
72+
func FromArray2X[Ty1, Ty2 any](arr [2]any) T2[Ty1, Ty2] {
7373
return FromSlice2X[Ty1, Ty2](arr[:])
7474
}
7575

7676
// FromSlice2 returns a tuple from a slice of length 2.
7777
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, an error is returned.
78-
func FromSlice2[Ty1 any, Ty2 any](values []any) (T2[Ty1, Ty2], error) {
78+
func FromSlice2[Ty1, Ty2 any](values []any) (T2[Ty1, Ty2], error) {
7979
if len(values) != 2 {
8080
return T2[Ty1, Ty2]{}, fmt.Errorf("slice length %d must match number of tuple values 2", len(values))
8181
}
@@ -94,7 +94,7 @@ func FromSlice2[Ty1 any, Ty2 any](values []any) (T2[Ty1, Ty2], error) {
9494

9595
// FromSlice2X returns a tuple from a slice of length 2.
9696
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, the function panics.
97-
func FromSlice2X[Ty1 any, Ty2 any](values []any) T2[Ty1, Ty2] {
97+
func FromSlice2X[Ty1, Ty2 any](values []any) T2[Ty1, Ty2] {
9898
if len(values) != 2 {
9999
panic(fmt.Errorf("slice length %d must match number of tuple values 2", len(values)))
100100
}

tuple3.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
// T3 is a tuple type holding 3 generic values.
8-
type T3[Ty1 any, Ty2 any, Ty3 any] struct {
8+
type T3[Ty1, Ty2, Ty3 any] struct {
99
V1 Ty1
1010
V2 Ty2
1111
V3 Ty3
@@ -47,7 +47,7 @@ func (t T3[Ty1, Ty2, Ty3]) GoString() string {
4747
}
4848

4949
// New3 creates a new tuple holding 3 generic values.
50-
func New3[Ty1 any, Ty2 any, Ty3 any](v1 Ty1, v2 Ty2, v3 Ty3) T3[Ty1, Ty2, Ty3] {
50+
func New3[Ty1, Ty2, Ty3 any](v1 Ty1, v2 Ty2, v3 Ty3) T3[Ty1, Ty2, Ty3] {
5151
return T3[Ty1, Ty2, Ty3]{
5252
V1: v1,
5353
V2: v2,
@@ -57,7 +57,7 @@ func New3[Ty1 any, Ty2 any, Ty3 any](v1 Ty1, v2 Ty2, v3 Ty3) T3[Ty1, Ty2, Ty3] {
5757

5858
// FromArray3 returns a tuple from an array of length 3.
5959
// If any of the values can not be converted to the generic type, an error is returned.
60-
func FromArray3[Ty1 any, Ty2 any, Ty3 any](arr [3]any) (T3[Ty1, Ty2, Ty3], error) {
60+
func FromArray3[Ty1, Ty2, Ty3 any](arr [3]any) (T3[Ty1, Ty2, Ty3], error) {
6161
v1, ok := arr[0].(Ty1)
6262
if !ok {
6363
return T3[Ty1, Ty2, Ty3]{}, fmt.Errorf("value at array index 0 expected to have type %s but has type %T", typeName[Ty1](), arr[0])
@@ -76,13 +76,13 @@ func FromArray3[Ty1 any, Ty2 any, Ty3 any](arr [3]any) (T3[Ty1, Ty2, Ty3], error
7676

7777
// FromArray3X returns a tuple from an array of length 3.
7878
// If any of the values can not be converted to the generic type, the function panics.
79-
func FromArray3X[Ty1 any, Ty2 any, Ty3 any](arr [3]any) T3[Ty1, Ty2, Ty3] {
79+
func FromArray3X[Ty1, Ty2, Ty3 any](arr [3]any) T3[Ty1, Ty2, Ty3] {
8080
return FromSlice3X[Ty1, Ty2, Ty3](arr[:])
8181
}
8282

8383
// FromSlice3 returns a tuple from a slice of length 3.
8484
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, an error is returned.
85-
func FromSlice3[Ty1 any, Ty2 any, Ty3 any](values []any) (T3[Ty1, Ty2, Ty3], error) {
85+
func FromSlice3[Ty1, Ty2, Ty3 any](values []any) (T3[Ty1, Ty2, Ty3], error) {
8686
if len(values) != 3 {
8787
return T3[Ty1, Ty2, Ty3]{}, fmt.Errorf("slice length %d must match number of tuple values 3", len(values))
8888
}
@@ -105,7 +105,7 @@ func FromSlice3[Ty1 any, Ty2 any, Ty3 any](values []any) (T3[Ty1, Ty2, Ty3], err
105105

106106
// FromSlice3X returns a tuple from a slice of length 3.
107107
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, the function panics.
108-
func FromSlice3X[Ty1 any, Ty2 any, Ty3 any](values []any) T3[Ty1, Ty2, Ty3] {
108+
func FromSlice3X[Ty1, Ty2, Ty3 any](values []any) T3[Ty1, Ty2, Ty3] {
109109
if len(values) != 3 {
110110
panic(fmt.Errorf("slice length %d must match number of tuple values 3", len(values)))
111111
}

tuple4.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
// T4 is a tuple type holding 4 generic values.
8-
type T4[Ty1 any, Ty2 any, Ty3 any, Ty4 any] struct {
8+
type T4[Ty1, Ty2, Ty3, Ty4 any] struct {
99
V1 Ty1
1010
V2 Ty2
1111
V3 Ty3
@@ -49,7 +49,7 @@ func (t T4[Ty1, Ty2, Ty3, Ty4]) GoString() string {
4949
}
5050

5151
// New4 creates a new tuple holding 4 generic values.
52-
func New4[Ty1 any, Ty2 any, Ty3 any, Ty4 any](v1 Ty1, v2 Ty2, v3 Ty3, v4 Ty4) T4[Ty1, Ty2, Ty3, Ty4] {
52+
func New4[Ty1, Ty2, Ty3, Ty4 any](v1 Ty1, v2 Ty2, v3 Ty3, v4 Ty4) T4[Ty1, Ty2, Ty3, Ty4] {
5353
return T4[Ty1, Ty2, Ty3, Ty4]{
5454
V1: v1,
5555
V2: v2,
@@ -60,7 +60,7 @@ func New4[Ty1 any, Ty2 any, Ty3 any, Ty4 any](v1 Ty1, v2 Ty2, v3 Ty3, v4 Ty4) T4
6060

6161
// FromArray4 returns a tuple from an array of length 4.
6262
// If any of the values can not be converted to the generic type, an error is returned.
63-
func FromArray4[Ty1 any, Ty2 any, Ty3 any, Ty4 any](arr [4]any) (T4[Ty1, Ty2, Ty3, Ty4], error) {
63+
func FromArray4[Ty1, Ty2, Ty3, Ty4 any](arr [4]any) (T4[Ty1, Ty2, Ty3, Ty4], error) {
6464
v1, ok := arr[0].(Ty1)
6565
if !ok {
6666
return T4[Ty1, Ty2, Ty3, Ty4]{}, fmt.Errorf("value at array index 0 expected to have type %s but has type %T", typeName[Ty1](), arr[0])
@@ -83,13 +83,13 @@ func FromArray4[Ty1 any, Ty2 any, Ty3 any, Ty4 any](arr [4]any) (T4[Ty1, Ty2, Ty
8383

8484
// FromArray4X returns a tuple from an array of length 4.
8585
// If any of the values can not be converted to the generic type, the function panics.
86-
func FromArray4X[Ty1 any, Ty2 any, Ty3 any, Ty4 any](arr [4]any) T4[Ty1, Ty2, Ty3, Ty4] {
86+
func FromArray4X[Ty1, Ty2, Ty3, Ty4 any](arr [4]any) T4[Ty1, Ty2, Ty3, Ty4] {
8787
return FromSlice4X[Ty1, Ty2, Ty3, Ty4](arr[:])
8888
}
8989

9090
// FromSlice4 returns a tuple from a slice of length 4.
9191
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, an error is returned.
92-
func FromSlice4[Ty1 any, Ty2 any, Ty3 any, Ty4 any](values []any) (T4[Ty1, Ty2, Ty3, Ty4], error) {
92+
func FromSlice4[Ty1, Ty2, Ty3, Ty4 any](values []any) (T4[Ty1, Ty2, Ty3, Ty4], error) {
9393
if len(values) != 4 {
9494
return T4[Ty1, Ty2, Ty3, Ty4]{}, fmt.Errorf("slice length %d must match number of tuple values 4", len(values))
9595
}
@@ -116,7 +116,7 @@ func FromSlice4[Ty1 any, Ty2 any, Ty3 any, Ty4 any](values []any) (T4[Ty1, Ty2,
116116

117117
// FromSlice4X returns a tuple from a slice of length 4.
118118
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, the function panics.
119-
func FromSlice4X[Ty1 any, Ty2 any, Ty3 any, Ty4 any](values []any) T4[Ty1, Ty2, Ty3, Ty4] {
119+
func FromSlice4X[Ty1, Ty2, Ty3, Ty4 any](values []any) T4[Ty1, Ty2, Ty3, Ty4] {
120120
if len(values) != 4 {
121121
panic(fmt.Errorf("slice length %d must match number of tuple values 4", len(values)))
122122
}

tuple5.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
// T5 is a tuple type holding 5 generic values.
8-
type T5[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any] struct {
8+
type T5[Ty1, Ty2, Ty3, Ty4, Ty5 any] struct {
99
V1 Ty1
1010
V2 Ty2
1111
V3 Ty3
@@ -51,7 +51,7 @@ func (t T5[Ty1, Ty2, Ty3, Ty4, Ty5]) GoString() string {
5151
}
5252

5353
// New5 creates a new tuple holding 5 generic values.
54-
func New5[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any](v1 Ty1, v2 Ty2, v3 Ty3, v4 Ty4, v5 Ty5) T5[Ty1, Ty2, Ty3, Ty4, Ty5] {
54+
func New5[Ty1, Ty2, Ty3, Ty4, Ty5 any](v1 Ty1, v2 Ty2, v3 Ty3, v4 Ty4, v5 Ty5) T5[Ty1, Ty2, Ty3, Ty4, Ty5] {
5555
return T5[Ty1, Ty2, Ty3, Ty4, Ty5]{
5656
V1: v1,
5757
V2: v2,
@@ -63,7 +63,7 @@ func New5[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any](v1 Ty1, v2 Ty2, v3 Ty3, v
6363

6464
// FromArray5 returns a tuple from an array of length 5.
6565
// If any of the values can not be converted to the generic type, an error is returned.
66-
func FromArray5[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any](arr [5]any) (T5[Ty1, Ty2, Ty3, Ty4, Ty5], error) {
66+
func FromArray5[Ty1, Ty2, Ty3, Ty4, Ty5 any](arr [5]any) (T5[Ty1, Ty2, Ty3, Ty4, Ty5], error) {
6767
v1, ok := arr[0].(Ty1)
6868
if !ok {
6969
return T5[Ty1, Ty2, Ty3, Ty4, Ty5]{}, fmt.Errorf("value at array index 0 expected to have type %s but has type %T", typeName[Ty1](), arr[0])
@@ -90,13 +90,13 @@ func FromArray5[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any](arr [5]any) (T5[Ty1
9090

9191
// FromArray5X returns a tuple from an array of length 5.
9292
// If any of the values can not be converted to the generic type, the function panics.
93-
func FromArray5X[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any](arr [5]any) T5[Ty1, Ty2, Ty3, Ty4, Ty5] {
93+
func FromArray5X[Ty1, Ty2, Ty3, Ty4, Ty5 any](arr [5]any) T5[Ty1, Ty2, Ty3, Ty4, Ty5] {
9494
return FromSlice5X[Ty1, Ty2, Ty3, Ty4, Ty5](arr[:])
9595
}
9696

9797
// FromSlice5 returns a tuple from a slice of length 5.
9898
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, an error is returned.
99-
func FromSlice5[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any](values []any) (T5[Ty1, Ty2, Ty3, Ty4, Ty5], error) {
99+
func FromSlice5[Ty1, Ty2, Ty3, Ty4, Ty5 any](values []any) (T5[Ty1, Ty2, Ty3, Ty4, Ty5], error) {
100100
if len(values) != 5 {
101101
return T5[Ty1, Ty2, Ty3, Ty4, Ty5]{}, fmt.Errorf("slice length %d must match number of tuple values 5", len(values))
102102
}
@@ -127,7 +127,7 @@ func FromSlice5[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any](values []any) (T5[T
127127

128128
// FromSlice5X returns a tuple from a slice of length 5.
129129
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, the function panics.
130-
func FromSlice5X[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any](values []any) T5[Ty1, Ty2, Ty3, Ty4, Ty5] {
130+
func FromSlice5X[Ty1, Ty2, Ty3, Ty4, Ty5 any](values []any) T5[Ty1, Ty2, Ty3, Ty4, Ty5] {
131131
if len(values) != 5 {
132132
panic(fmt.Errorf("slice length %d must match number of tuple values 5", len(values)))
133133
}

tuple6.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
// T6 is a tuple type holding 6 generic values.
8-
type T6[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any] struct {
8+
type T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6 any] struct {
99
V1 Ty1
1010
V2 Ty2
1111
V3 Ty3
@@ -53,7 +53,7 @@ func (t T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6]) GoString() string {
5353
}
5454

5555
// New6 creates a new tuple holding 6 generic values.
56-
func New6[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any](v1 Ty1, v2 Ty2, v3 Ty3, v4 Ty4, v5 Ty5, v6 Ty6) T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6] {
56+
func New6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6 any](v1 Ty1, v2 Ty2, v3 Ty3, v4 Ty4, v5 Ty5, v6 Ty6) T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6] {
5757
return T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6]{
5858
V1: v1,
5959
V2: v2,
@@ -66,7 +66,7 @@ func New6[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any](v1 Ty1, v2 Ty2,
6666

6767
// FromArray6 returns a tuple from an array of length 6.
6868
// If any of the values can not be converted to the generic type, an error is returned.
69-
func FromArray6[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any](arr [6]any) (T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6], error) {
69+
func FromArray6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6 any](arr [6]any) (T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6], error) {
7070
v1, ok := arr[0].(Ty1)
7171
if !ok {
7272
return T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6]{}, fmt.Errorf("value at array index 0 expected to have type %s but has type %T", typeName[Ty1](), arr[0])
@@ -97,13 +97,13 @@ func FromArray6[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any](arr [6]any
9797

9898
// FromArray6X returns a tuple from an array of length 6.
9999
// If any of the values can not be converted to the generic type, the function panics.
100-
func FromArray6X[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any](arr [6]any) T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6] {
100+
func FromArray6X[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6 any](arr [6]any) T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6] {
101101
return FromSlice6X[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6](arr[:])
102102
}
103103

104104
// FromSlice6 returns a tuple from a slice of length 6.
105105
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, an error is returned.
106-
func FromSlice6[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any](values []any) (T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6], error) {
106+
func FromSlice6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6 any](values []any) (T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6], error) {
107107
if len(values) != 6 {
108108
return T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6]{}, fmt.Errorf("slice length %d must match number of tuple values 6", len(values))
109109
}
@@ -138,7 +138,7 @@ func FromSlice6[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any](values []a
138138

139139
// FromSlice6X returns a tuple from a slice of length 6.
140140
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, the function panics.
141-
func FromSlice6X[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any](values []any) T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6] {
141+
func FromSlice6X[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6 any](values []any) T6[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6] {
142142
if len(values) != 6 {
143143
panic(fmt.Errorf("slice length %d must match number of tuple values 6", len(values)))
144144
}

tuple7.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
// T7 is a tuple type holding 7 generic values.
8-
type T7[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any, Ty7 any] struct {
8+
type T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7 any] struct {
99
V1 Ty1
1010
V2 Ty2
1111
V3 Ty3
@@ -55,7 +55,7 @@ func (t T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7]) GoString() string {
5555
}
5656

5757
// New7 creates a new tuple holding 7 generic values.
58-
func New7[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any, Ty7 any](v1 Ty1, v2 Ty2, v3 Ty3, v4 Ty4, v5 Ty5, v6 Ty6, v7 Ty7) T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7] {
58+
func New7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7 any](v1 Ty1, v2 Ty2, v3 Ty3, v4 Ty4, v5 Ty5, v6 Ty6, v7 Ty7) T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7] {
5959
return T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7]{
6060
V1: v1,
6161
V2: v2,
@@ -69,7 +69,7 @@ func New7[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any, Ty7 any](v1 Ty1,
6969

7070
// FromArray7 returns a tuple from an array of length 7.
7171
// If any of the values can not be converted to the generic type, an error is returned.
72-
func FromArray7[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any, Ty7 any](arr [7]any) (T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7], error) {
72+
func FromArray7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7 any](arr [7]any) (T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7], error) {
7373
v1, ok := arr[0].(Ty1)
7474
if !ok {
7575
return T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7]{}, fmt.Errorf("value at array index 0 expected to have type %s but has type %T", typeName[Ty1](), arr[0])
@@ -104,13 +104,13 @@ func FromArray7[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any, Ty7 any](a
104104

105105
// FromArray7X returns a tuple from an array of length 7.
106106
// If any of the values can not be converted to the generic type, the function panics.
107-
func FromArray7X[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any, Ty7 any](arr [7]any) T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7] {
107+
func FromArray7X[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7 any](arr [7]any) T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7] {
108108
return FromSlice7X[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7](arr[:])
109109
}
110110

111111
// FromSlice7 returns a tuple from a slice of length 7.
112112
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, an error is returned.
113-
func FromSlice7[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any, Ty7 any](values []any) (T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7], error) {
113+
func FromSlice7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7 any](values []any) (T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7], error) {
114114
if len(values) != 7 {
115115
return T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7]{}, fmt.Errorf("slice length %d must match number of tuple values 7", len(values))
116116
}
@@ -149,7 +149,7 @@ func FromSlice7[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any, Ty7 any](v
149149

150150
// FromSlice7X returns a tuple from a slice of length 7.
151151
// If the length of the slice doesn't match, or any of the values can not be converted to the generic type, the function panics.
152-
func FromSlice7X[Ty1 any, Ty2 any, Ty3 any, Ty4 any, Ty5 any, Ty6 any, Ty7 any](values []any) T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7] {
152+
func FromSlice7X[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7 any](values []any) T7[Ty1, Ty2, Ty3, Ty4, Ty5, Ty6, Ty7] {
153153
if len(values) != 7 {
154154
panic(fmt.Errorf("slice length %d must match number of tuple values 7", len(values)))
155155
}

0 commit comments

Comments
 (0)