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

Mojo function

sorted

def sorted[cmp: def(IntTuple, IntTuple) thin -> Bool = __lt__](tuple: IntTuple) -> 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 (def(IntTuple, IntTuple) thin -> 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): The IntTuple to be sorted.

Returns:

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

Was this page helpful?