No splat operator / no variadic function currying
| Originator: | Jamil.Dhanani | ||
| Number: | rdar://18863107 | Date Originated: | 03-Nov-2014 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Reproducible: |
Summary: Currently in Swift, there's no way to expand a list or dictionary to arguments in a function. This would be especially useful for functions with variadic arguments. For example, say 'sum' is defined as: func sum<Int>(ints: Int...) There should be a way to say: args = [1,2,3] sum(*args) which would expand the list into arguments to the function. This would also be useful for function currying. Right now, it would be impossible to define a truly generic curry function for variadic functions, like so: func curry<T>(f: ((T -> Any...) -> Any), value: T) -> ((Any...) -> Any) Swift's embracing of higher-order functions is somewhat mitigated by the fact that this isn't supported. Steps to Reproduce: Try writing a generic function for currying a variadic function Expected Results: I expected that I would find apply, or a splat operator like Python's *args, 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.
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!