2

How do I access a function through a list?

I have something like this:

  List processList = [
    [001, 'Volume', 0.8,0,0],
    [002, 'Complexity', 0.5,0,0],
    [003, 'Silence', 0.3,0,0],
    [004, 'Notice', 0.3,0,0],
    ....];

And I want 001, 002 etc to be functions that I can call through

processList[i][0] ();

Like a list of functions...

I cannot figure out the syntax for this somehow, the only thing I can achieve is filling the List with the result of the function, but that is not what I need.

1 Answer 1

3

Try

void main() {
  List processList = [
    [(){print('London');}, 'Volume', 0.8, 0, 0],
    [(){print('Aarhus');}, 'Complexity', 0.5, 0, 0],
    [(){print('Munich');}, 'Silence', 0.3, 0, 0],
    [(){print('LA');}, 'Notice', 0.3, 0, 0],
  ];
  int i = 3;
  processList[i][0]();
}

prints LA. Looks at typedefs for ways to declare function signatures.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.