IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

reduce

reduce[reducer: def(a: Int, b: IntTuple) capturing -> Int](t: IntTuple, initializer: Int) -> Int

Apply a reduction function to an IntTuple with an initial value.

This function iterates through each element of the IntTuple and applies the provided reduction function cumulatively, starting with the initializer.

Parameters:

  • reducer (def(a: Int, b: IntTuple) capturing -> Int): A function that combines the accumulated result with the next element.

Args:

  • t (IntTuple): The IntTuple to reduce.
  • initializer (Int): The initial value for the reduction operation.

Returns:

Int: The final accumulated result after applying the reduction function to all elements in the IntTuple.