Boolean type and operations.
Import from the core package to use this module.
motoko name=import
import Bool "mo:core/Bool";
While boolean operators _ and _ and _ or _ are short-circuiting,
avoiding computation of the right argument when possible, the functions
logicalAnd(_, _) and logicalOr(_, _) are strict and will always evaluate both
of their arguments.
Example:
motoko include=import
let t = true;
let f = false;
// Short-circuiting AND
assert not (t and f);
// Short-circuiting OR
assert t or f;Booleans with constants true and false.
public func logicalAnd(self : Bool, other : Bool) : BoolReturns a and b.
Example:
motoko include=import
assert not Bool.logicalAnd(true, false);
assert Bool.logicalAnd(true, true);public func logicalOr(self : Bool, other : Bool) : BoolReturns a or b.
Example:
motoko include=import
assert Bool.logicalOr(true, false);
assert Bool.logicalOr(false, true);public func logicalXor(self : Bool, other : Bool) : BoolReturns exclusive or of a and b, a != b.
Example:
motoko include=import
assert Bool.logicalXor(true, false);
assert not Bool.logicalXor(true, true);
assert not Bool.logicalXor(false, false);public func logicalNot(self : Bool) : BoolReturns not bool.
Example:
motoko include=import
assert Bool.logicalNot(false);
assert not Bool.logicalNot(true);public func equal(self : Bool, other : Bool) : BoolReturns a == b.
Example:
motoko include=import
assert Bool.equal(true, true);
assert not Bool.equal(true, false);public func compare(self : Bool, other : Bool) : Order.OrderReturns the ordering of a compared to b.
Returns #less if a is false and b is true,
#equal if a equals b,
and #greater if a is true and b is false.
Example:
motoko include=import
assert Bool.compare(true, false) == #greater;
assert Bool.compare(true, true) == #equal;
assert Bool.compare(false, true) == #less;public func toText(self : Bool) : TextReturns a text value which is either "true" or "false" depending on the input value.
Example:
motoko include=import
assert Bool.toText(true) == "true";
assert Bool.toText(false) == "false";