According to the following source code it seems that regular lambdas are interchangeable with extension lambdas.
fun main(args: Array<String>) {
val numbers = listOf(1, 2, 3)
filter(numbers, predicate)
filter(numbers, otherPredicate)
println("PREDICATE: ${predicate} " +
"\nOTHERPREDICATE: ${otherPredicate} " +
"\nEQUALITY: ${predicate==otherPredicate}")
}
val predicate : Int.() -> Boolean = {this % 2 != 0}
val otherPredicate : (Int) -> Boolean = {it % 2 != 0}
fun filter(list: List<Int>, predicate:(Int) -> Boolean) {
for(number in list){
if(predicate(number)){
println(number)
}
}
}
The output (I care about), is the following:
PREDICATE: kotlin.Int.() -> kotlin.Boolean
OTHERPREDICATE: (kotlin.Int) -> kotlin.Boolean
EQUALITY: false
The question is why are these lambdas interchangeable? Shouldn't be something different? Is the compiler doing something "smart" under the hood?