I have a function that takes the following as a pa...
# getting-started
k
I have a function that takes the following as a parameter:
validator: ValidationContext.(String?) -> ValidationMessage?
So I think I need to provide a function that takes in a
ValidationContext
and gives out a
ValidationMessage
, but what is up with the
.(String?)
. I don’t understand what the signature of my function should be.
k
The type of that
validator
variable is "A lambda where
ValidationContext
is the receiver, with one parameter of type
String?
(nullable string), returning a `ValidationMessage?`"
k
So that means I would make an extension function on ValidationContext like this?
fun ValidationContext.myValidator(myString: String?): ValidationMessage?
?
oh wait a lambda
it has to be a lambda?
so I have to put the parameter in curly braces
okay it all just clicked, thank you 👍
👍 1
k
It doesn't _ have_ to be a lambda, you could also pass a function reference
::myValidator