File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff 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+
20912115How do you work with errors?
20922116
20932117- Throwing or propagating an error stops iteration over the value pack.
You can’t perform that action at this time.
0 commit comments