Skip to main content
Log in

Mojo function

depth

depth(src: IntTuple[origin]) -> Int

Calculates the maximum nesting depth of an IntTuple.

This function recursively traverses the IntTuple structure to determine its maximum nesting depth. A scalar value has depth 0, a flat tuple has depth 1, and nested tuples increase the depth accordingly.

Example:

```mojo
from layout.layout_tuple import depth

print(depth(1)) # prints 0
print(depth((1, 2))) # prints 1
print(depth((1, (1, 2)))) # prints 2
```
.
```mojo
from layout.layout_tuple import depth

print(depth(1)) # prints 0
print(depth((1, 2))) # prints 1
print(depth((1, (1, 2)))) # prints 2
```
.

Args:

  • src (IntTuple[origin]): The IntTuple to measure the depth of.

Returns:

An integer representing the maximum nesting depth.