[swift-evolution] [Pitch] Flattening the function type of unapplied instance methods

Kevin Lundberg kevin at klundberg.com
Mon Feb 22 19:41:53 CST 2016


On 2/22/2016 6:18 PM, Joe Groff wrote:
>
> If I understand the intent of `weakify` correctly, I think this kind
> of use case is already pretty severely curtailed by our removing the
> tuple splat feature, since you can no longer make `weakify` generic
> across multiple method signatures. Like the tuple splat feature, an
> explicit variadic splatting feature ought to make this possible for
> flattened method signatures:
>
>     func weakify<Class: class, Args, Result>(instance: Class, method:
>     (Class, Args...) -> Result) -> (Args...) -> Result {
>       return {[weak instance] args... in method(instance, args...) }
>     }
>
>
> -Joe

Agreed on the tuple splat removal point, but the common use cases I use
this for today don't apply weakify to methods with more than one
argument in practice. Even so, your example here is admittedly a pretty
simple change to make to keep existing functionality if the curried form
of this goes away, and this language change would make it haeder for
people who want to do something similar to create a retain cycle
scenario if they don't use something like weakify to safely pass method
references around.

I do like the current behavior, but given this you've convinced me that
it may be best for it to change :)

- Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160222/8a7aa328/attachment.html>


More information about the swift-evolution mailing list