[swift-evolution] [Discussion] Here we go again: Extension Functions
Stephen Celis
stephen.celis at gmail.com
Fri Feb 26 11:32:34 CST 2016
> On Feb 26, 2016, at 7:21 AM, Pierre Monod-Broca via swift-evolution <swift-evolution at swift.org> wrote:
>
> I'm less convinced by the suggested syntax, to me it feels a bit weird.
>
> I'm thinking an attribute on the closure's first parameter, for exemple (feel free to suggest other names):
>
> func with<T>(value: T, body: (bound T) -> ()) -> T {
> body(value)
> return value
> }
While I'm not married to `T.() -> ()`, I do like that it:
- Separates the self parameter from the parameter list
- Avoids an additional keyword
We could also try reusing the recently removed curry syntax:
func with<T>(value: T, body: (T)() -> Void) -> T {
value.body(value)
return value
}
Given that curried versions of instance methods are available on the class, and given the fact that the instance versions of these methods have a bound `self` (and would likely have an extension function signature), it might make more sense than using dot-notation.
Stephen
More information about the swift-evolution
mailing list