This code prints "Hello 1". parseInput
have two generic types, the first arg is a simple object of the first generic type A, the second arg is a function which suppose to change the generic type A to generic B. As you can see it works fine in the following.
fun toGreeting(input : Int) : String {
return "hello " + input
}
fun <A, B> parseInput(raw : A, toB : (raw : A) -> B) : B {
return toB(raw)
}
fun main(args: Array<String>) {
val greeting = parseInput(1, ::toGreeting)
println(greeting)
}
The question is how can I give a default lambda value for the second named argument in the parseInput
. So I can call this function by just providing the first argument, and having it to use the default lambda function.
val greeting = parseInput(1)
println(greeting)