June 2022
Intermediate to advanced
130 pages
2h 45m
English
Anonymous functions, also called higher order functions, allow developers to treat functions like data. You can pass anonymous functions as arguments, or hold them in variables.
You can then use anonymous functions to automate the code we’ve written so far. Sometimes, you might want to build your own function to combine elements in a list. Take another look at the critical line of code that uses an accumulator:
| | total_with_accumulator(rest, partial_total + first) |
Now that you know how that works, let’s organize the code with a slight difference:
| | process_list(rest, arbitrary_function) |
This pattern is common enough that there’s a function to do this work called reduce. To use it, we need to be able to specify our ...
Read now
Unlock full access