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

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.val

Implemented traits

AnyType

Required methods

__bool__

__bool__(self: _Self) -> Bool

Get the boolean representation of the value.

Returns:

Bool: The boolean representation of the value.