Bool
public struct Bool { /* private fields */ }Two-state truth value with true and false as its only inhabitants.
Bool is the canonical conformer of every logical, conditional, and
equality protocol in std.core: equality, matching, hashing, formatting,
and/or/not, plus FFI compatibility for crossing the C boundary as
a single byte. Custom types rarely need to wrap Bool; conform to the
individual protocols (e.g. BooleanConditional) instead.
Examples
let alive = true;
if alive { greet() }
let votes = [true, false, true];
let yesCount = votes.iter().filter { it }.count(); // 2
Representation
Wraps a single lang.i1. The runtime promotes to a byte at FFI
boundaries (FFISafe conformance).
Initializers
public init(boolLiteral: lang.i1)
public init(boolLiteral: lang.i1)Builds a Bool from the primitive lang.i1 produced by a literal.
ImplementsEquatable
Associated Types
type Output = Bool
type Output = BoolMethods
public func equal(to: Self) -> Bool
public func equal(to: Self) -> BoolBridges Equal.equal(to:) to Equatable.isEqual(to:).
public func isEqual(to: Bool) -> Bool
public func isEqual(to: Bool) -> BoolReturns true if both bits agree. Drives == for Bool.
public func notEqual(to: Self) -> Bool
public func notEqual(to: Self) -> BoolDefault !=: delegates to == so there's a single source of truth.
ImplementsMatchable
Methods
public func matches(Bool) -> Bool
public func matches(Bool) -> BoolPattern-match form of isEqual: case true => and case false =>
dispatch through here.
ImplementsFormattable
Methods
public func format(into: mutating StringBuilder, FormatOptions)
public func format(into: mutating StringBuilder, FormatOptions)Renders as "true" / "false". With options.debug, wraps as
"Bool(true)" / "Bool(false)" for diagnostic dumps.
Examples
true.format() // "true"
false.format(FormatOptions.debug()) // "Bool(false)"public func formatted(FormatOptions) -> String
public func formatted(FormatOptions) -> StringReturns this value rendered as a String.
Convenience wrapper: creates a StringBuilder, calls
format(into:), and returns the built string. Uses a distinct
name to avoid overload-resolution ambiguity with format(into:).
ImplementsHashable
Methods
public func hash[H](into: mutating H) where H: Hasher
public func hash[H](into: mutating H) where H: HasherFeeds a single 0 or 1 byte into hasher. Compatible with how the
stdlib hashes other primitives — equal Bools always hash equal.
ImplementsAnd
Associated Types
type Output = Bool
type Output = Booltype Output = Bool
type Output = Booltype Output = Bool
type Output = BoolMethods
public func logicalAnd(() -> Bool) -> Bool
public func logicalAnd(() -> Bool) -> BoolShort-circuiting and: other runs only when self is true.
The closure form is what the and keyword lowers into; users
typically write a and b rather than calling this directly.
ImplementsOr
Associated Types
type Output
type OutputMethods
public func logicalOr(() -> Bool) -> Bool
public func logicalOr(() -> Bool) -> BoolShort-circuiting or: other runs only when self is false.
ImplementsNot
Associated Types
type Output
type OutputMethods
public func logicalNot() -> Bool
public func logicalNot() -> BoolBit-flip; not true == false.
ImplementsExpressibleByBoolLiteral
Initializers
init(boolLiteral: lang.i1)
init(boolLiteral: lang.i1)Builds an instance from a boolean literal.
ImplementsBooleanConditional
Methods
public func boolValue() -> lang.i1
public func boolValue() -> lang.i1Returns the wrapped lang.i1 so if/while can branch on it
without a redundant Bool round-trip.
Defined in lang/std/core/bool.ks