'How to assign a default value to a function as parameter in Kotlin

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 1:[1]

Yes it is possible

fun myFun(book: String, isCool: (book: String) -> Boolean = { _ -> true }) {
    if (isCool(book)) println("$book is cool!")
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yunus Dilber