File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,36 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
5
5
6
6
## Swift 5.7
7
7
8
+ * [ SE-0326] [ ] :
9
+
10
+ It's now possible to infer parameter and result types from the body of a multi-statement
11
+ closure. The distinction between single- and multi-statement closures has been removed.
12
+
13
+ Use of closures becomes less cumbersome by removing the need to constantly specify explicit
14
+ closure types which sometimes could be pretty large e.g. when there are multiple parameters
15
+ or a complex tuple result type.
16
+
17
+ For example:
18
+
19
+ ``` swift
20
+ func map <T >(fn : (Int ) -> T) -> T {
21
+ return fn (42 )
22
+ }
23
+
24
+ func computeResult <U : BinaryInteger >(_ : U) -> U { /* processing */ }
25
+
26
+ let _ = map {
27
+ if let $0 < 0 {
28
+ // do some processing
29
+ }
30
+
31
+ return computeResult ($0 )
32
+ }
33
+ ```
34
+
35
+ The result type of ` map ` can now be inferred from the body of the trailing closure
36
+ passed as an argument.
37
+
8
38
* [ SE-0345] [ ] :
9
39
10
40
It is now possible to unwrap optional variables with a shorthand syntax that
@@ -9119,6 +9149,7 @@ Swift 1.0
9119
9149
[SE- 0343 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
9120
9150
[SE- 0340 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0340-swift-noasync.md>
9121
9151
[SE- 0345 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
9152
+ [SE- 0326 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
9122
9153
9123
9154
[SR- 75 ]: < https: // bugs.swift.org/browse/SR-75>
9124
9155
[SR- 106 ]: < https: // bugs.swift.org/browse/SR-106>
You can’t perform that action at this time.
0 commit comments