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]
): TheIntTuple
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 twoIntTuple
s into a single resultIntTuple
.
Args:
- t (
IntTuple[origin]
): TheIntTuple
to reduce.
Returns:
The final accumulated result after applying the reduction function to all elements in the IntTuple
.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!