reduce

Returns the result of combining the elements of collection and initial-value according to function.

If collection is empty, reduce returns initial-value; otherwise, function is applied to initial-value and the first element of collection to produce a new value.  If more elements remain in the collection, then function is called again, this time with the value from the previous application and the next element from collection.  This process continues until all elements of collection have been processed.

function is a binary function used to combine all the elements of collection into a single value.  Processing is always done in the natural order for collection.

define variable high-score = 10
reduce (max, high-score, #(3, 1, 4, 1, 5, 9))
⇒ 10
reduce (max, high-score, #(3, 12, 9, 8, 8, 6))
⇒ 12

Exported from

Modifiers

open

Arguments

functionAn instance of <function>.
initial-valueAn instance of <object>.
collectionAn instance of <collection>.

Values

valueAn instance of <object>.
Returns the result of combining the elements of collection and initial-value according to function.
The common-dylan module.
Whenever possible, we have tried to keep the Dylan module pristine and unextended, preferring to add our extensions to separate modules or libraries.
The class of objects that can be applied to arguments.
The class of all Dylan objects.
The class of collections, aggregate data structures.