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:
@value
struct Foo(Boolable):
var val: Bool
fn __bool__(self) -> Bool:
return self.val
Implemented traitsβ
AnyType
Methodsβ
__bool__
β
__bool__(self: T) -> Bool
Get the boolean representation of the value.
Returns:
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!
If you'd like to share more information, please report an issue on GitHub
π What went wrong?