[swift-users] Tuple Member Extraction in Closure Parameters
David Sweeris
davesweeris at mac.com
Thu May 5 10:09:03 CDT 2016
Seems like a nice feature, though. I think it'd be worth starting a thread on the evolution list. I don't know if it would be done in time for 3.0, but it doesn't hurt to try.
- Dave Sweeris
> On May 5, 2016, at 09:54, Matthew Johnson via swift-users <swift-users at swift.org> wrote:
>
> Destructuring of parameters would be pretty cool. If it gets added to Swift it should be a general feature for all functions, not just on closures. There are a lot of design directions and subtleties that would need to be explored. I doubt it is something that will be considered in the Swift 3 timeframe.
>
>> On May 5, 2016, at 9:43 AM, Dennis Weissmann via swift-users <swift-users at swift.org> wrote:
>>
>> Thanks Krzysztof, you’re right! I totally forgot about that neat feature.
>>
>> However, there’s no way to do this directly in the parameter list, right?
>>
>> Do you think such feature should exist?
>>
>> - Dennis
>>
>>>> On May 5, 2016, at 4:19 PM, Krzysztof Siejkowski <krzysztof at siejkowski.net> wrote:
>>>>
>>>>
>>>> A workaround is to declare two local variables:
>>>>
>>>> let e = zip(a,b).reduce(0) { acc, tuple in
>>>> let value1 = tuple.0
>>>> let value2 = tuple.1
>>>> return acc + value1 + value2
>>>> }
>>>
>>> You can also get away with one assignment:
>>>
>>> let ok = zip(a,b).reduce(0) { acc, tuple in
>>> let (value1, value2) = tuple
>>> return acc + value1 + value2
>>>
>>> }
>>>
>>> Best,
>>> Krzysztof
>>
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160505/b0a17de4/attachment.html>
More information about the swift-users
mailing list