¿Cómo se define una matriz de funciones (funciones) en Kotlin?
Esta es mi suposición de cómo se haría...
this.funs = arrayOf : Unit( this::openCamera, this::sendSMS, this::makeCall )¿Cómo invocaría cada elemento de la matriz como una función en tiempo de ejecución? ¿Simplemente especificar 'funs' en lugar de openCamera(), sendSMS() y MakeCall() en un bucle forEach() funcionaría?
o... es esta la forma en que invocaría cada función:
val function = getFunction(funs) function()Si tuviera algunas funciones definidas como
fun one() { print("ONE") } fun two() { print("TWO") } fun three() { print("THREE") }Luego puede crear una matriz de estos como
fun someFun(){ val arrayOfFunctions: Array<() -> Unit> = arrayOf(::one, ::two, ::three) arrayOfFunctions.forEach { function -> function() } }