0

My use case is this: a function called 'time' that will return how long it takes to run any function you give it.

So the time function needs to know all the parameters to pass into the function when it calls it.

I know how to pass a function into another function, but how can I pass all its parameters, without knowing in advance how many and what type they are, so they can be used when calling the function?

For example, if I pass in an array of all the parameters I need to send, is there some Dart way to call a function by expanding an array into a list of parameters? Or perhaps there's another way to capture and pass a function call, including all parameters, as one executable object?

I'm also interested in knowing if there's a more Dartful way to accomplish what I'm trying to do re: timing function calls.

Mike Miller
  • 3,368
  • 5
  • 36
  • 49

1 Answers1

0

I believe using a List of parameters with the apply method is the most common way and practical of doing this and I have seen something similar used to pass parameters for JS interop. As far as I know, there isn't a way to expand an array into a list of parameters like you can for javascript. You could of course create your own object to pass arguments, but I think it would add unnecessary complexity and end up being more difficult.

Example of passing parameters to function in dart:js here.

Christopher Moore
  • 15,626
  • 10
  • 42
  • 52