I’m trying to provide a default value for a functi...
# getting-started
e
I’m trying to provide a default value for a function parameter but have been unable to get the syntax right (and it’s hard to search for function parameters that are themselves functions). Could someone tell me how to correct this?
Copy code
fun Payload.toString(errorReporter: (String) -> Unit = { (_: String) -> Unit } )String? { ... }
I’m getting the “Declaration destructuring initializer” error.
The default function should ignore its string argument. If someone wants to pass in a logger, they can.
s
lambda parameters in parens are interpreted as destructured parameters
remove the parens around
_: String
(and add the missing
:
after the closing paren of the argument list) and you’ll be golden
🥇 1
e
Thank you. Removing the parens did the trick. (I’m not sure where my colon went in the copy-paste.)
👍 1