Skip to content

Commit 9db2e32

Browse files
committed
Update outline for new tuple behavior.
Confirmed the code examples here and in SE-0399 work as of Swift 5.9 (swiftlang-5.9.0.120.7)
1 parent 6c4d271 commit 9db2e32

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

TSPL.docc/LanguageGuide/Generics.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,30 @@ How do you access the values of a parameter pack?
20882088
there isn't a way to iterate over the values in a pack ---
20892089
the SE proposal calls that out as a potential future direction.
20902090

2091+
- When a function returns a tuple using pack expansion,
2092+
or otherwise created by expanding a value pack,
2093+
you can perform the same operations on that tuple
2094+
as if it were still an unexpanded parameter pack.
2095+
This doesn't include tuples created any other way,
2096+
or tuples that contain a mix of elements created this way and another way.
2097+
2098+
For example:
2099+
2100+
<!-- from SE-0399 -->
2101+
```swift
2102+
func tuplify<each T>(_ value: repeat each T) -> (repeat each T) {
2103+
return (repeat each value)
2104+
}
2105+
2106+
func example<each T>(_ value: repeat each T) {
2107+
let abstractTuple = tuplify(repeat each value)
2108+
repeat print(each abstractTuple) // Ok
2109+
2110+
let concreteTuple = (true, "two", 3)
2111+
repeat print(each concreteTuple) // Invalid
2112+
}
2113+
```
2114+
20912115
How do you work with errors?
20922116

20932117
- Throwing or propagating an error stops iteration over the value pack.

0 commit comments

Comments
 (0)