Re. the syntax for variadics (...
vs #pack
vs variadic
etc), has borrowing from glob or regex syntax been considered? I’m spurred in particular by the notion that a variadic would have a length of zero or more, which is useful sometimes but other times makes for a lot of boilerplate in having to write, if you want to require at least one parameter, something like:
func foo<T1: Sequence, variadic T2: Sequence>(_ first: T1, _ rest: T2) where T1 == T2 {
// Or whatever the syntax is for meaning T1 must be the same type as T2.
...
}
What if instead you could write:
func foo<T: Sequence+>(_ values: T) {
...
}
In cases where you do want to allow for zero parameters:
func foo<T: Sequence*>(_ values: T) {
...
}
Then more powerfully, where you require at least two but not more than eight:
func foo<T: Sequence{2,8}>(_ values: T) {
...
}
Or as a shorthand for a specific number of parameters:
func foo<T: Sequence{4}>(_ values: T) {
// I require exactly four parameters, all conforming to Sequence.
...
}
// Today this would have to be:
func foo<T: Sequence>(_ value1: T, _ value2: T, _ value3: T, _ value4: T) {
...
}
// Or (depending on your true intent):
func foo<T1: Sequence, T2: Sequence, T3: Sequence, T4: Sequence>(_ value1: T1, _ value2: T2, _ value3: T3, _ value4: T4) {
...
}
There might be a distinction between using the modifiers on the generic name’s declaration vs in the parameter list - to me the former suggests T
could be distinct types sharing some common trait (e.g. all Sequence
s), while the latter could be more naturally a way to say a given argument is actually a tuple of some number of elements all of which are the same type.
I haven’t thought it through further than that, but even if it doesn’t prove sensible, I recommend it be included in the ‘Alternatives considered’ section for future reference.