How do I find the return type of this curried function?

58 Views Asked by At
addition(int a) => (int b) => (int c) => a+b+c;

This is the function which returns dynamic for now

when I call addition(1)(2)(3) it prints 6 that's fine

I want to know the exact return type of this function

I am trying out the currying concept!!

2

There are 2 best solutions below

0
julemand101 On BEST ANSWER

As Rahul say's, the current type, of the returned value, in your example would be dynamic. But if we want to apply a static know type it would be something like:

int Function(int) Function(int) addition(int a) =>
    (int b) => (int c) => a + b + c;

void main() {
  print(addition.runtimeType);
  // (int) => (int) => (int) => int
}
2
Rahul On

It should be dynamic. When nothing is specified, dynamic is the return type.

This statement could be broken as

addition(int a) {
  return (int b) {
    return (int c) {
      return a+b+c;
    };
  };
}

Here as none of the functions have any return type, they all have return type of dynamic