|
4 | 4 | > This is in reverse chronological order, so newer entries are added to the top.
|
5 | 5 |
|
6 | 6 | ## Swift 6.0
|
| 7 | +* [SE-0408][]: |
| 8 | + A `for`-`in` loop statement can now accept a pack expansion expression, |
| 9 | + enabling iteration over the elements of its respective value pack. This form |
| 10 | + supports pattern matching, control transfer statements, and other features |
| 11 | + available to a `Sequence`-driven `for`-`in` loop, except for the `where` |
| 12 | + clause. Below is an example implementation of the equality operator for |
| 13 | + tuples of arbitrary length using pack iteration: |
| 14 | + |
| 15 | + ```swift |
| 16 | + func == <each Element: Equatable>(lhs: (repeat each Element), |
| 17 | + rhs: (repeat each Element)) -> Bool { |
| 18 | + |
| 19 | + for (left, right) in repeat (each lhs, each rhs) { |
| 20 | + guard left == right else { return false } |
| 21 | + } |
| 22 | + return true |
| 23 | + } |
| 24 | + ``` |
| 25 | + |
| 26 | + The elements of the value pack corresponding to the pack expansion expression |
| 27 | + are evaluated on demand, meaning the i<sup>th</sup> element is evaluated on |
| 28 | + the i<sup>th</sup> iteration: |
| 29 | + |
| 30 | + ```swift |
| 31 | + func doSomething(_: some Any) {} |
| 32 | + |
| 33 | + func evaluateFirst<each T>(_ t: repeat each T) { |
| 34 | + for _ in repeat doSomething(each t) { |
| 35 | + break |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + evaluateFirst(1, 2, 3) |
| 40 | + // 'doSomething' will be called only on the first element of the pack. |
| 41 | + ``` |
| 42 | + |
7 | 43 | * [SE-0352][]:
|
8 | 44 | The Swift 6 language mode will open existential values with
|
9 | 45 | "self-conforming" types (such as `any Error` or `@objc` protocols)
|
@@ -10147,6 +10183,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
|
10147 | 10183 | [SE-0394]: https://github.com/apple/swift-evolution/blob/main/proposals/0394-swiftpm-expression-macros.md
|
10148 | 10184 | [SE-0397]: https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md
|
10149 | 10185 | [SE-0407]: https://github.com/apple/swift-evolution/blob/main/proposals/0407-member-macro-conformances.md
|
| 10186 | +[SE-0408]: https://github.com/apple/swift-evolution/blob/main/proposals/0408-pack-iteration.md |
10150 | 10187 | [SE-0411]: https://github.com/apple/swift-evolution/blob/main/proposals/0411-isolated-default-values.md
|
10151 | 10188 | [SE-0417]: https://github.com/apple/swift-evolution/blob/main/proposals/0417-task-executor-preference.md
|
10152 | 10189 | [SE-0412]: https://github.com/apple/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md
|
|
0 commit comments