I cannot understand why the wrong function is illegal in Kotlin
fun right1() : (String) -> String {
return {
when {
it.isEmpty() -> "Empty"
else -> it.reversed()
}
}
}
fun wrong() : (String) -> String {
return fun(s: String): String {
when {
s.isEmpty() -> "Empty"
else -> s.reversed()
}
}
}
fun right2() : (String) -> String {
return {
s: String ->
when {
s.isEmpty() -> "Empty"
else -> s.reversed()
}
}
}
It seems to be that I can only return lambda functions and non anonymous ones.
Sorry for the trivial question, I am a Kotlin newbye.