Gifted Slacker

Found in the Darnedest Places

Posted in Software by Grant on June 30th, 2008

Nice concise definitions of closures, map, fold, unfold and filter sneaked their way into the middle of a Dr. Dobbs article (via Raganwald):

Closures, are anonymous functions created at run-time which can refer to variables that are visible where the function is declared.

Closures are especially useful when performing operations over elements in a collection. The most common collection operations (aggregate operations) in functional programming are map, filterfold, and unfold operations.

A map operation transforms a list into a new same-sized list by applying a transformation function (such as a closure) to each element in the original list. A common example of a map operation is when performing a vector scaling operation.

A filter operation creates a list from another list using only those items for which a predicate function returns true.

The fold operation combines values in a list using a binary function and an initial value. A summation function is a simple example of a fold operation.

The unfold operation creates a list from an initial value and by successively applying a generator function, until a terimination predicate returns true.

These are usually defined in much more obfuscated terms. It’s good to see them so clearly defined.

Leave a Reply