@@ -1889,7 +1889,7 @@ even though the doubling operation could really apply
1889
1889
to any number of arguments.
1890
1890
1891
1891
Other approaches that also have drawbacks
1892
- include taking the arguments an array or a variadic parameter,
1892
+ include taking the arguments as an array or a variadic parameter,
1893
1893
which requires all arguments to be the same type,
1894
1894
or using ` Any ` which erases type information.
1895
1895
@@ -1905,12 +1905,11 @@ func double<each T: Numeric>(_ value: repeat each T) -> (repeat each T) {
1905
1905
}
1906
1906
```
1907
1907
1908
- In the code above, ` Element ` is a generic type parameter.
1909
- It's marked ` each Element ` ,
1910
- indicating that it's a type-parameter pack.
1908
+ In the code above, ` each T ` is declared in a generic parameter list.
1909
+ It's marked with ` each ` , indicating that it's a type parameter pack.
1911
1910
In contrast to a generic type parameter,
1912
1911
which serves as a placeholder for a single type,
1913
- a type- parameter pack is a placeholder for multiple types.
1912
+ a type parameter pack is a placeholder for multiple types.
1914
1913
The ability to have ` T ` contain a varying number of types
1915
1914
is what allows this version of ` double(_:) `
1916
1915
to take any number of parameters
@@ -1933,7 +1932,7 @@ extension Numeric {
1933
1932
}
1934
1933
1935
1934
let numbers = [12 , 0.5 , 8 as Int8 ]
1936
- let doubledNumbers = double (numbers)
1935
+ let doubledNumbers = doubled (numbers)
1937
1936
```
1938
1937
1939
1938
The value of ` doubledNumbers ` is ` (24, 1.0, 16) ` ,
@@ -1980,7 +1979,7 @@ How do you create a parameter pack?
1980
1979
and in function argument lists.
1981
1980
1982
1981
``` swift
1983
- func f <each T >(_ t : repeat each T) -> repeat each T
1982
+ func f <each T >(_ t : repeat each T) -> ( repeat each T)
1984
1983
```
1985
1984
1986
1985
- The expansion pattern is repeated for every element in the given type pack
@@ -2035,8 +2034,8 @@ How do you constrain the types in a parameter pack?
2035
2034
- In the more complex case,
2036
2035
use ` repeat each T ` in a trailing ` where ` clause.
2037
2036
2038
- - You must restrict the types that appear in a type- parameter pack;
2039
- conformance requirements don't implicitly propagate .
2037
+ - You must restrict the types that appear in a type parameter pack
2038
+ if its expansion will be used as a restricted generic type parameter .
2040
2039
For example, given ` each T: Hashable ` writing ` repeat Set<each T> ` works,
2041
2040
but it doesn't work with just ` each T `
2042
2041
because ` Set ` requires ` T ` to be hashable but the pack doesn't.
@@ -2062,7 +2061,7 @@ How do you access the values of a parameter pack?
2062
2061
```
2063
2062
2064
2063
- The result (and its type) of expanding a parameter pack
2065
- vary depending on the number of elements in the pack.
2064
+ within a tuple vary depending on the number of elements in the pack.
2066
2065
Zero-element packs produce ` () ` ,
2067
2066
single-element packs produce a simple type,
2068
2067
and multi-element packs produce a tuple type.
@@ -2073,7 +2072,7 @@ How do you access the values of a parameter pack?
2073
2072
2074
2073
For example,
2075
2074
` repeat (each T, Int) ` is different from ` (repeat each T, Int) ` .
2076
- The former makes multiple tuple ` (T1, Int) ... (Tn, Int) ` ,
2075
+ The former makes multiple tuples ` (T1, Int) ... (Tn, Int) ` ,
2077
2076
expanding ` T ` and adding ` Int ` to each tuple.
2078
2077
The latter makes one tuple, ` (T1, ..., Tn, Int) ` .
2079
2078
Other code can come between ` repeat ` and ` each ` ---
0 commit comments