Fantastic proposal, thank you for pushing variadic generics forward!
Admittedly, I wasn't pleased with repeat each
at first given its length, but after spending some time with the last snapshots, I have to say it started growing on me. In a sense, if repeat Int
where allowed, then an hypothetical repeat 10 Int
could be seen as a "natural" extension to spell out [Pitch] Improved Compiler Support for Large Homogenous Tuples - #3 by Michael_Gottesman.
For clarification purposes, code that was working with the 2023-03-30 snapshot, isn't working with the 2023-04-01 one:
typealias Map<Base, Result> = Result
protocol P { var foo: String { get } }
extension Int: P { var foo: String { "integer!" } }
extension Double: P { var foo: String { "floating point number!" } }
extension [Int]: P { var foo: String { "list of integers!" } }
func foos<each S: P>(of p: repeat each S) -> (repeat Map<each S, String>) {
return (repeat (each p).foo)
}
let r = foos(of: [1], 2.0, 3)
print(r)
The Map
typealias is there only to provide a same-shape requirement between (repeat each S)
and (repeat String)
. Is this the intended (or an intended) way to procede? Is it expected to work?