Not sure if this is the best approach but I want to have functions accessible by an index and would prefer not to use a dictionary. So I was thinking of putting them into an array.
var array = [ func1, func2, ... ]
It looks like this is possible since functions are first class citizens.
BUt I'm wondering if you can do this on classes. That is, pass a function from a class instance to an array, without losing performance with extra closures.
class Foo {
var array: [Function]
init() {
array = [ f1, f2 ]
}
func f1() {
return array.length
}
func f2(a: Int, b: Int) {
// ... the functions are all different.
}
}
Wondering if anything like that is possible.