Mojo trait
Boolable
The Boolable trait describes a type that can be explicitly converted to a Bool or evaluated as a boolean expression in if or while conditions.
This trait requires the type to implement the __bool__() method. For
example:
struct Foo(Boolable):
var val: Bool
def __bool__(self) -> Bool:
return self.valImplemented traitsโ
AnyType,
ImplicitlyDestructible
Required methodsโ
__bool__โ
__bool__(self: _Self) -> Bool
Get the boolean representation of the value.
Returns:
Bool: The boolean representation of the value.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!