34 lines
635 B
Go
34 lines
635 B
Go
package helper
|
|
|
|
// we have several places where a function returns multiple values,
|
|
// and collecting them into an array so that we can treat them as a single value
|
|
// is convenient.
|
|
|
|
func collect3[T any](a, b, c T) [3]T {
|
|
return [3]T{a, b, c}
|
|
}
|
|
|
|
func collect4[T any](a, b, c, d T) [4]T {
|
|
return [4]T{a, b, c, d}
|
|
}
|
|
|
|
// it's also convenient to permute these things, for
|
|
// tests where the order shouldn't matter.
|
|
|
|
var permuteOrder3 = [][3]int{
|
|
{0, 1, 2},
|
|
{0, 2, 1},
|
|
{1, 0, 2},
|
|
{1, 2, 0},
|
|
{2, 0, 1},
|
|
{2, 1, 0},
|
|
}
|
|
|
|
func permute3[T any](in [3]T, order [3]int) (out [3]T) {
|
|
for i, j := range order {
|
|
out[i] = in[j]
|
|
}
|
|
|
|
return
|
|
}
|