Name

list::reduce — Reduces a list to a single value.

Synopsis

flex1 list::reduce ( flex1 x ,
  flex2 y ,
  flex1 value ,
  list<flex2> list ,
  block<flex1> expression );
 

Parameters

flex1 x

flex2 y

flex1 value

list<flex2> list

block<flex1> expression

Return

flex1

Description

Apply expression cumulatively to the values of the list, from left to right, to reduce the list to a single value. See http://en.wikipedia.org/wiki/Reduce_(higher-order_function) for a detailed explanation.

In this version the initial value is explicitly provided. Thus the list can be empty. Also the return type can be different from the type of the list.

Usage

  list::reduce (integer x, integer y, 0, [2, 4, 6], { return x + y; }) -> 12
 

  list::reduce (integer x, integer y, 1, [2, 4, 6], { return x * y; }) -> 48
 
 

  list::reduce (term t, float f, `item(`id(`dummy)), [3.14, 2.71], { return add(t, tostring(f)); }) -> `item (`id (`dummy), "3.14", "2.71")