The shape of the function would be
func variableCartesianProduct<each T>(input: repeat [each T]) -> [(repeat each T)]
The use case here is as input for parameterized tests. I'd like to take lists of possible inputs and produce all combinations of those lists. I've made a few attempts, but I think there are some missing pieces. You could build up recursive tuples, but I can't figure out a way to flatten them. ie you can't do a transformation of an arbitrary tuple shaped like ((String, Int), Float)
to a tuple shaped like (String, Int, Float)
. You could track a list of indices to combine, but there's no way to do something like
// Should produce a tuple
(repeat each input).enumerate().map { index, list in list[indices[index]] }
as far as I can tell. In other words, you can't alter the function call based on the parameter pack index.
I'd love some help on this if it's possible! Thanks!