accumulate-as ( ... seq identity quot: ( ... prev elt -- ... next ) exemplar -- ... final newseq )
Factor documentation > Factor handbook > The language > Collections > Sequence operations > Sequence combinators
Prev:accumulate ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... final newseq )
Next:accumulate! ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... final seq )


Vocabulary
sequences

Inputs and outputs
seqa sequence
identityan object
quota quotation with stack effect ( ... prev elt -- ... next )
exemplara sequence
finalthe final result
newseqa new sequence


Word description
Combines successive elements of the sequence using a binary operation, and outputs a sequence of the same type as exemplar containing intermediate results, together with the final result.

The first element of the new sequence is identity. Then, on the first iteration, the two inputs to the quotation are identity, and the first element of the old sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the old sequence.

When given the empty sequence, outputs an empty sequence together with the identity.

Definition
USING: kernel sequences.private ;

IN: sequences

: accumulate-as
( ... seq identity quot: ( ... prev elt -- ... next ) exemplar -- ... final newseq )
[ (accumulate) ] dip map-as ; inline