Swift: Overload function call syntax

Originator:rix.rob
Number:rdar://18141648 Date Originated:26-Aug-2014 07:47 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta6 (6A280e)
Classification:Enhancement Reproducible:Always
 
Summary:
It’s often convenient to wrap functions in a structure of some description which operates like the function while maintaining some state or associated behaviour.

Actually calling the wrapped behaviour would be much more convenient if function call syntax were overloadable similarly to read-only subscripting or operator overloading:

struct F<T, U> {
	let f: T -> U

	call(x: T) -> U { // subscript–style syntax
		return f(x)
	}
}

postfix func ()<T, U> (f: F<T, U>, x: T) -> U { // operator–style syntax
	return f.f(x)
}


One can already define a method named `call` or similar, but it’s rather noisier syntactically.


Steps to Reproduce:
N/A


Expected Results:
N/A


Actual Results:
N/A


Regression:
N/A


Notes:
N/A

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!