I'm wondering if there's an equivalent to Swift's @autoclosure feature
Essentially, I want to be able to create an argument in a function or constructor/initializer that can take another function that takes parameters, and execute it:
class Step(handler: () -> Unit) {
init {
handler()
}
}
Step(aFunctionThatTakesParameters(parameter: String)) // <- Is there a way to get something like this working?
For reference, the equivalent code in Swift looks like this:
struct Step {
init(_ handler: @autoclosure () -> Void) {
handler()
}
}
Step(aFunctionThatTakesParameters(parameter: ""))