Fun with anonymous methods – using higher-order functions
Since Version 2009, the Delphi language (or better, its Object Pascal dialect) supports anonymous methods. What's an anonymous method? Not surprisingly, an anonymous method is a procedure or a function that does not have an associated name.
An anonymous method treats a block of code just like a value so that it can be assigned to a variable or used as a parameter to a method or returned by a function as its result value. In addition, an anonymous method can refer to variables and bind values to the variables in the context scope in which the anonymous method is defined. Anonymous methods are similar to closures defined in other languages such as JavaScript or C#. An anonymous method is declared as a reference to a method:
type TFuncOfString = reference to function(S: String): String;
Anonymous methods (or anonymous functions) are convenient to pass as an argument to a higher-order function. What's a higher-order...