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

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

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

Prev: | each-index ( ... seq quot: ( ... elt index -- ... ) -- ... ) |

Next: | interleave ( ... seq between quot: ( ... elt -- ... ) -- ... ) |

Vocabulary

sequences

Inputs

Outputs

Word description

Combines successive elements of the sequence using a binary operation, and outputs the final result. On the first iteration, the two inputs to the quotation are identity, and the first element of the sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the sequence.

Examples

Definition

sequences

Inputs

seq | a sequence |

identity | an object |

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

Outputs

result | the final result |

Word description

Combines successive elements of the sequence using a binary operation, and outputs the final result. On the first iteration, the two inputs to the quotation are identity, and the first element of the sequence. On successive iterations, the first input is the result of the previous iteration, and the second input is the corresponding element of the sequence.

Examples

USING: math prettyprint sequences ;
{ 1 5 3 } 0 [ + ] reduce .

9

9

Definition

This documentation was generated offline from a
`load-all`

image. If you want, you can also
browse the documentation from within the UI developer tools. See
the Factor website
for more information.

Factor 0.100 x86.64 (2270, heads/master-9a858f779b, Jun 12 2024 16:13:38)