Skip to main content
Log in

Mojo function

sorted

sorted[cmp: fn[ImmutableOrigin, ImmutableOrigin](IntTuple[$0], IntTuple[$1]) -> Bool = lt[::Origin[::Bool](tuple: IntTuple[origin]) -> IntTuple

Sort an IntTuple using the provided comparison function.

This function implements a merge sort algorithm to efficiently sort the elements of an IntTuple. The sorting is stable and has O(n log n) time complexity.

Parameters:

  • cmp (fn[ImmutableOrigin, ImmutableOrigin](IntTuple[$0], IntTuple[$1]) -> Bool): A comparison function that takes two IntTuple elements and returns True if the first should come before the second. Defaults to the lt function which performs lexicographical ordering.

Args:

  • tuple (IntTuple[origin]): The IntTuple to be sorted.

Returns:

A new IntTuple containing the same elements as the input but sorted according to the comparison function.