Linked Questions

Popular Questions

Pass a typed function as a parameter in Dart

Asked by At

I know the Function class can be passed as a parameter to another function, like this:

void doSomething(Function f) {

But is there a way to constrain the arguments and the return type of the function parameter?

For instance, in this case f is being invoked directly on an integer, but what if it was a function accepting a different type?

I tried passing it as a Function<Integer>, but Function is not a parametric type.

Is there any other way to specify the signature of the function being passed as a parameter?

Related Questions