[swift-evolution] Improved Trailing Closure Syntax
Nicholas Maccharoli
nmaccharoli at gmail.com
Wed Dec 28 22:58:20 CST 2016
Swift Evolution,
Swift's API Design Guidelines are really good in my opinion, but I believe
there is
ambiguity with current trailing closure syntax.
Take for example if there were three variations of a `subscribe`function:
func subscribe(onNext block: @escaping (Event) -> Void) { ... }
func subscribe(onError block: @escaping (Event) -> Void) { ... }
func subscribe(onCompleted block: @escaping (Event) -> Void) { ... }
Since using subscribe with trailing closure syntax would cause ambiguity:
subscribe { event in ... }
The only option available is to call the function as normal:
subscribe(onNext: { event in ... })
Since these functions are distinguished by their argument label, if a
variation of trailing closure syntax were introduced that provided the
option of using an argument label in parenthesis this ambiguity would
disappear.
something like this:
subscribe(onNext:) { event in ... }
would allow using trailing closure syntax in this case.
Just a thought, I personally think having this change to the language would
be worthwhile but would love to hear the community's opinion.
- Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161229/dc47f15c/attachment.html>
More information about the swift-evolution
mailing list