November 2014
Intermediate to advanced
150 pages
3h 25m
English
Passing an anonymous function into an iterator like forEach already demonstrates some nice support for first-class objects—the ability to treat functions as variables that can be assigned and passed around.
Dart’s functional programming capabilities are strong enough to support things like partial function application. The classic example of partial application is converting an add function that returns the sum of three numbers into another function that fixes one of those numbers.
| functional_programming/first_order.dart | |
| | add(x, y, z) { |
| | return x + y + z; |
| | } |
| | makeAdder2(fn, arg1) { |
| | return (y, z) { |
| | return fn(arg1, y, z); |
| | }; |
| | } |
| | var add10 = makeAdder2(add, 10); |
The name partial application comes from returning ...
Read now
Unlock full access