Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fun String.extension(): String = removePrefix("hello")
val lambda: (String) -> String = { it.removePrefix("hello") }
val lambdaWithReceiver: String.() -> String = { removePrefix("hello") }
fun function(arg: (String) -> String) {
}
fun function2(arg: String.() -> String) {
}
// Which of the below do or don't compile?
//function(String::extension)
//function2(String::extension)
//function(lambda)
//function2(lambda)
//function(lambdaWithReceiver)
//function2(lambdaWithReceiver)
//var variable: (String) -> String = lambda
//variable = lambdaWithReceiver
//variable = String::extension
//var variable2: String.() -> String = lambdaWithReceiver
//variable2 = lambda
//variable2 = String::extension
//val assignment: String.() -> String = { arg: String -> "" }
//val assignment2: String.() -> String = lambda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.