Reduction to index

Syntax

	$list.indexReduce($index-fun, $unit, $reduce-fun)

Description

Creates a dictionary from the entries of a list. The key values are calculated from list elements using the indexing function. A value of the resulting dictionary consists of the reduction of all list elements for which the same key value was calculated. The first reduction step is performed with the passed neutral element and the first list element of a key.

If the same key value k was calculated for the list elements e1, e5 and e7, then the value $reduceFun($reduceFun($reduceFun($unit, e1), e5), e7) is stored in the resulting dictionary under the key k.

Parameter

Name Type Description Mandatory Default
list Set A list from which a dictionary should be generated. yes
index-fun Function Function that assigns a key value to a list item. yes
unit Number/string Neutral element of reduce-fun. yes
reduce-fun Function Function that reduces multiple list values with the same key value to one element. yes

Return value

Type: Business object

A dictionary containing all list elements that have been assigned key values according to the index-fun and reduce-fun functions.

Examples

Number of equal list elements

	{
   list = list("Martin", "Tom", "Eric", "Martin", "Eric", "Lars", "Steven", "Steven", "Eric");
   indexfun = string -> $string;
   reducefun = subtotal -> $subtotal + 1;
   $list.indexReduce($indexfun, 0, $reducefun);
}

Output: Dictionary with the following values:

{
  Martin=2.0, 
  Tom=1.0, 
  Eric=3.0, 
  Lars=1.0, 
  Steven=2.0
}