Bool
Module
Implements the Bool class.
Bool
The primitive Bool scalar value used in Mojo.
Fields:
value
The underlying storage of the boolean value.
Functions:
__init__
__init__(value: i1) -> Self
Construct a Bool value given a __mlir_type.i1 value.
Args:
- value (
i1
): The initial __mlir_type.i1 value.
Returns:
The constructed Bool value.
__init__(value: scalar<bool>) -> Self
__bool__
__bool__(self: Self) -> Self
Convert to Bool.
Returns:
This value.
__mlir_i1__
__mlir_i1__(self: Self) -> i1
Convert this Bool to __mlir_type.i1.
This method is a special hook used by the compiler to test boolean objects in control flow conditions. It should be implemented by Bool but not other general boolean convertible types (they should implement __bool__
instead).
Returns:
The underlying value for the Bool.
__invert__
__invert__(self: Self) -> Self
Inverts the Bool value.
Returns:
True if the object is false and False otherwise.
__eq__
__eq__(self: Self, rhs: Self) -> Self
Compare this Bool to RHS.
Performs an equality comparison between the Bool value and the argument. This method gets invoked when a user uses the ==
infix operator.
Args:
- rhs (
Self
): The rhs value of the equality statement.
Returns:
True if the two values match and False otherwise.
__ne__
__ne__(self: Self, rhs: Self) -> Self
Compare this Bool to RHS.
Performs a non-equality comparison between the Bool value and the argument. This method gets invoked when a user uses the !=
infix operator.
Args:
- rhs (
Self
): The rhs value of the non-equality statement.
Returns:
False if the two values do match and True otherwise.
__and__
__and__(self: Self, rhs: Self) -> Self
Compute self & rhs
.
Bitwise and’s the Bool value with the argument. This method gets invoked when a user uses the and
infix operator.
Args:
- rhs (
Self
): The rhs value of the and statement.
Returns:
self & rhs
.
__or__
__or__(self: Self, rhs: Self) -> Self
Compute self | rhs
.
Bitwise or’s the Bool value with the argument. This method gets invoked when a user uses the or
infix operator.
Args:
- rhs (
Self
): The rhs value of the or statement.
Returns:
self | rhs
.
__xor__
__xor__(self: Self, rhs: Self) -> Self
Compute self ^ rhs
.
Bitwise Xor’s the Bool value with the argument. This method gets invoked when a user uses the ^
infix operator.
Args:
- rhs (
Self
): The rhs value of the xor statement.
Returns:
self ^ rhs
.
__rand__
__rand__(self: Self, value: Self) -> Self
Return value & self
.
Args:
- value (
Self
): The other value.
Returns:
value & self
.
__ror__
__ror__(self: Self, value: Self) -> Self
Return value | self
.
Args:
- value (
Self
): The other value.
Returns:
value | self
.
__rxor__
__rxor__(self: Self, value: Self) -> Self
Return value ^ self
.
Args:
- value (
Self
): The other value.
Returns:
value ^ self
.