https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

Daniele B

03/12/2021, 8:25 PM
I would like to use a block function like this one inside an extension function:
Copy code
fun MyModel.anExtensionFunction() {
	objectLambda {
	     it.getText()
	}
}
where it is the obj property of the MyModel class How should I write the objectLambda function in order to do so?
Copy code
class MyModel {
    var obj = MyObject()
    fun objectLambda() {
         // HOW SHOULD I WRITE THIS FUNCTION?
    }
}

class MyObject {
    fun getText() = "myText"
}
e

ephemient

03/12/2021, 8:45 PM
well it wants to take the lambda block as an argument, right?
Copy code
fun objectLambda(block: (MyObject) -> Unit) {
    block(obj)
}
👍 1
d

Daniele B

03/12/2021, 10:00 PM
thanks