
上QQ阅读APP看书,第一时间看更新
Getting ready
In this recipe, you'll see how to use Delphi's anonymous methods with some of the most popular and useful higher-order functions:
- Map: This is available in many functional programming languages. This takes as arguments a func function and a list of elements list, and returns a new list with func applied to each element of list.
- Reduce: This is also known as Fold. This requires a combining function, a starting point for a data structure, and possibly some default values to be used under certain conditions. The Reduce function proceeds to combine elements of the data structure using the injected function. This is used to perform operations on a set of values to get only one result (or a smaller set of values) that represents the reduction of that initial data. For example, the values 1, 2, and 3 can be reduced to the single value 6 using the SUM .
- Filter: This requires a data structure and a filter condition. This returns all the elements in the structure that match the filter condition.