accumulate-as ( ... seq identity quot: ( ... prev elt -- ... next ) exemplar -- ... final newseq )

Factor handbook » The language » Collections » Sequence operations » Sequence combinators

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 ) -- ... newseq ) |

Vocabulary

sequences

Inputs and outputs

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 output sequence is identity. Then, 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 a new empty sequence together with the identity.

Notes

May be named scan or prefix sum in other languages.

See also

accumulate, accumulate!, accumulate*, accumulate*!, accumulate*-as

Definition

sequences

Inputs and outputs

seq | a sequence |

identity | an object |

quot | a quotation with stack effect ( ... prev elt -- ... next ) |

exemplar | a sequence |

final | the final result |

newseq | a 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 output sequence is identity. Then, 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 a new empty sequence together with the identity.

Notes

May be named scan or prefix sum in other languages.

See also

accumulate, accumulate!, accumulate*, accumulate*!, accumulate*-as

Definition

: accumulate-as

( ... seq identity quot: ( ... prev elt -- ... next ) exemplar -- ... final newseq )

[ (accumulate) ] dip map-as ; inline

( ... seq identity quot: ( ... prev elt -- ... next ) exemplar -- ... final newseq )

[ (accumulate) ] dip map-as ; inline