Issue
In my Kotlin project I would like to assign a default value to a function passed as a parameter, something like:
fun myFun(book: String, isCool: (book: String) -> Boolean = _ -> true) {
if (isCool(book)) println("$book is cool!")
}
Is this possible?
Solution
Yes it is possible
fun myFun(book: String, isCool: (book: String) -> Boolean = { _ -> true }) {
if (isCool(book)) println("$book is cool!")
}
Answered By - Yunus Dilber
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.