Skip to main content

Mojo trait

Comparable

A type which can be compared for order with other instances of itself.

Implementers of this trait must define the __lt__ and __eq__ methods.

The default implementations of the default comparison methods can be potentially inefficent for types where comparison is expensive. For such types, it is recommended to override all the default implementations.

Implemented traits

AnyType, EqualityComparable, UnknownDestructibility

Aliases

__del__is_trivial

alias __del__is_trivial

A flag (often compiler generated) to indicate whether the implementation of __del__ is trivial.

The implementation of __del__ is considered to be trivial if:

  • The struct has a compiler-generated trivial destructor and all its fields have a trivial __del__ method.

In practice, it means that the __del__ can be considered as no-op.

Required methods

__lt__

__lt__(self: _Self, rhs: _Self) -> Bool

Define whether self is less than rhs.

Args:

  • rhs (_Self): The value to compare with.

Returns:

Bool: True if self is less than rhs.

__eq__

__eq__(self: _Self, other: _Self) -> Bool

Define whether two instances of the object are equal to each other.

Args:

  • other (_Self): Another instance of the same type.

Returns:

Bool: True if the instances are equal according to the type's definition of equality, False otherwise.

Provided methods

__le__

__le__(self: _Self, rhs: _Self) -> Bool

Define whether self is less than or equal to rhs.

Args:

  • rhs (_Self): The value to compare with.

Returns:

Bool: True if self is less than or equal to rhs.

__ne__

__ne__(self: _Self, other: _Self) -> Bool

Define whether two instances of the object are not equal to each other.

Args:

  • other (_Self): Another instance of the same type.

Returns:

Bool: True if the instances are not equal according to the type's definition of equality, False otherwise.

__gt__

__gt__(self: _Self, rhs: _Self) -> Bool

Define whether self is greater than rhs.

Args:

  • rhs (_Self): The value to compare with.

Returns:

Bool: True if self is greater than rhs.

__ge__

__ge__(self: _Self, rhs: _Self) -> Bool

Define whether self is greater than or equal to rhs.

Args:

  • rhs (_Self): The value to compare with.

Returns:

Bool: True if self is greater than or equal to rhs.

Was this page helpful?