Reputation: 9574
I am saving my function call like this
val savedFun = { myFunction("Ali", "[email protected]") }
I can call it latter like this savedFun()
and its working perfectly fine.
But I want to save multiple calls in a list and then call them one by one. How can I achieve that?
Upvotes: 0
Views: 506
Reputation: 3894
You should be able to store your functions in a List<() -> Unit>
:
val listOfFun: MutableList<() -> Unit> = mutableListOf()
listOfFun += { myFunction("Ali", "[email protected]") }
listOfFun += { myFunction("AnotherPerson", "[email protected]") }
And execute your functions from the list:
listOfFun.forEach { it() }
Upvotes: 2