@value struct Foo(Sized):
    var length: Int

    fn __len__(self) -> Int:
        return self.length

var foo = Foo(42)
print(len(foo) == 42)  // Output: True

Overview

The len function and its associated traits Sized and SizedRaising are integral parts of the Mojo programming language, designed to provide a standardized way to obtain the length of various data types, such as strings and arrays. These built-in functionalities enable developers to work with data structures more efficiently by allowing them to easily determine the size or length of these structures.

Key Features

Use Cases

Considerations

Compatibility