Swift: There is apparently no splat operator, apply function, or any way to write either

Originator:rix.rob
Number:rdar://17493976 Date Originated:27-Jun-2014 11:23 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta2 (6A216f)
Classification:Serious Bug Reproducible:Always
 
Summary:
Given a function f and an array a, there is apparently no way to do any of the following:

- call f with the sequential elements of a
- call f with some explicit parameters followed by the sequential elements of a
- call a variadic function f in either of the above manners


Steps to Reproduce:
1. Try to generalize the 404 Advanced Swift memoize combinator ( <3 ) to n arguments, as might be important if you’re trying to build a memoizing == operator as I am.



Expected Results:
I expected that I would find apply, or a splat operator like Ruby’s *foo, or some other way to call a function with its arguments provided in an array.


Actual Results:
I could not find any such operator or function.


Regression:
N/A


Notes:
Not only does this not appear to exist, it doesn’t appear to be possible to write it. This is pretty damaging, as it means that generalizations to different numbers of arguments each have to be implemented separately.

Further, you can’t compose variadics, which immediately makes them a second class citizen.

My workaround for the moment is to return a variadic function which calls the supplied body with an array of parameters instead of applying; that works here, but won’t work everywhere.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!