Skip to main content

Mojo function

reduce

reduce[reducer: fn[?, origin: ImmutableOrigin](a: Int, b: IntTuple[origin]) capturing -> Int](t: IntTuple[origin], 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 (fn[?, origin: ImmutableOrigin](a: Int, b: IntTuple[origin]) 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.

Was this page helpful?