-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enh(swift) add parameter pack keywords #3803
enh(swift) add parameter pack keywords #3803
Conversation
5d7ed4d
to
22b47fb
Compare
So what is repeat when used outside a generic? |
It's a general mechanism for destructuring and composing type/value packs, so it's supported in more contexts than just generic parameter lists. This is a good example from the proposal, the keyword can be used in the context of a parameter pack directly: struct Pair<First, Second> {
init(_ first: First, _ second: Second)
}
func makePairs<each First, each Second>(
firsts first: repeat each First,
seconds second: repeat each Second
) -> (repeat Pair<each First, each Second>) {
return (repeat Pair(each first, each second))
}
let pairs = makePairs(firsts: 1, "hello", seconds: true, 1.0)
// 'pairs' is '(Pair(1, true), Pair("hello", 2.0))' |
Is it not a keyword in those other contexts? |
It is a keyword in those contexts as well, it's already in the "keywords" list though because it's already used for loops. repeat {
print(number)
number += 1
} while number <= 20 |
Ah that's what I was missing. 😀 |
Parameter packs are supported in Swift 5.9
Their usage can be seen in SE-0393. This essentially just requires a promotion of
each
to a keyword and matchingrepeat
andeach
as keywords in generic parameters.Changes
repeat
andeach
parameter pack keywords.Checklist
CHANGES.md