Default value of parameter in function type


#1

I try it and they give me a error, wy it is unsupported?

I do not want to pass error value every time that I call the callback.
Please explain-me. Tanks


#2

(Boolean, String) -> Unit is the type of callback, so as it is not a function it cannot have default arguments.


#3

Thanks for that. Can you give me some example in how can I have default arguments in that case?


#4

Make a couple of functions that you can call in the implementations of register(...):

fun success(callback: (Boolean, String) -> Unit) {
    callback(true, "")
}

fun error(callback: (Boolean, String) -> Unit, message: String) {
    callback(false, message)
}

In the register(...) implementations you can then use either of these lines:

success(callback)
error(callback, "Error message")

#5

Sounds good, thanks.