Reputation: 31
I am learning Dart, and I can't understand the logic behind this code if anyone can help:
Function applyMultiplier(num multiplier) {
return (num value) {
return value * multiplier;
};
}
final triple = applyMultiplier(3);
print(triple(6)); //output 18
What I don't understand is how did we pass from triple to value. I can't understand the logic behind.
Upvotes: 0
Views: 30
Reputation: 1219
Well, the function applyMultiplier takes a num as argument and returns a function that itself returns the value it is given multiplied by another multiplier. final tripple = applyMultiplier(3)
stores this function that is returned from applyMultiplier in the variable triple. Because the variable triple then stores a function it can also be used like a function.
Upvotes: 1