Skip to main content
Log in

Mojo function

reduce

reduce[: origin.set, //, T: AnyTrivialRegType, func: fn[ImmutableOrigin](a: T, b: IntTuple[$0]) capturing -> T](t: IntTuple[origin], initializer: T) -> T

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:

  • T (AnyTrivialRegType): A trivial register type that can be used for accumulation.
  • func (fn[ImmutableOrigin](a: T, b: IntTuple[$0]) capturing -> T): A function that combines the accumulated result with the next element.

Args:

  • t (IntTuple[origin]): The IntTuple to reduce.
  • initializer (T): The initial value for the reduction operation.

Returns:

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

reduce[: origin.set, //, reducer: fn[ImmutableOrigin, ImmutableOrigin](a: IntTuple[$0], b: IntTuple[$1]) capturing -> IntTuple](t: IntTuple[origin]) -> IntTuple

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

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

Parameters:

  • reducer (fn[ImmutableOrigin, ImmutableOrigin](a: IntTuple[$0], b: IntTuple[$1]) capturing -> IntTuple): A function that combines two IntTuples into a single result IntTuple.

Args:

  • t (IntTuple[origin]): The IntTuple to reduce.

Returns:

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