reduce-index ( ... seq identity quot: ( ... prev elt index -- ... next ) -- ... result )


Vocabulary
sequences

Inputs
seqa sequence
identityan object
quota quotation with stack effect ( ... prev elt index -- ... next )


Outputs
resultan object


Word description
Combines successive elements of the sequence and their indices binary operations, and outputs the final result. On the first iteration, the three inputs to the quotation are identity, the first element of the sequence, and its index, 0. On successive iterations, the first input is the result of the previous iteration, the second input is the corresponding element of the sequence, and the third is its index.

Examples
USING: sequences prettyprint math ; { 10 50 90 } 0 [ + + ] reduce-index .
153


Definition


: reduce-index
( ... seq identity quot: ( ... prev elt index -- ... next ) -- ... result )
swapd each-index ; inline