accumulate*! ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... seq )
Factor handbook » The language » Collections » Sequence operations » Destructive sequence operations

Prev:accumulate! ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... final seq )
Next:change-nth ( ..a i seq quot: ( ..a elt -- ..b newelt ) -- ..b )


Vocabulary
sequences

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


Outputs
seqa sequence


Word description
Combines successive elements of the sequence using a binary operation, and outputs the original sequence of all results.

On the first iteration, the two inputs to the quotation are identity and the first element of the input sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the next element of the input sequence.

When given the empty sequence, outputs the same empty sequence.

Errors
Throws an error if the sequence is immutable, or the sequence cannot hold elements of the type output by quot.

Side effects
Modifies seq

Examples
USING: math prettyprint sequences ; { 2 2 2 2 2 } 0 [ + ] accumulate*! .
{ 2 4 6 8 10 }


Notes
May be named scan or prefix sum in other languages.

See also
accumulate, accumulate!, accumulate-as, accumulate*, accumulate*-as

Definition


: accumulate*!
( ... seq identity quot: ( ... prev elt -- ... next ) -- ... seq )
(accumulate*) map! nip ; inline