[swift-evolution] Apply for closure
Tino Heth
2th at gmx.de
Thu Jan 28 07:07:15 CST 2016
I have no obvious use case, but I like the concept of "functions having functions":
It is most likely not that relevant for Swift 3, but as soon as the macro-system becomes concrete, it could be valuable for meta-programming…
Besides "apply", we could have introspection ("f.parametersByIndex[0].type") and a revival of currying
let twice: (Double) -> Double = *.curry(parameterIndex: 0, value: 2.0)
It could even be possible to do meta-programming without leaving the language, e.g.
class Snitch: SomeClass {
for f in super.overridableMethods {
self.implementation[f] = { (args: f.argumentTuple) in
print("Function \(f.name) has been called with \(args)")
return f.apply(args)
}
}
}
I probably would hate anyone actually using such a feature (unless the debugger is really great ;-), but it would be freaking cool nonetheless ;-)
Tino
More information about the swift-evolution
mailing list