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)

Builds a Bool from the primitive lang.i1 produced by a literal.

ImplementsEquatable

Associated Types

type Output = Bool

Methods

public func equal(to: Self) -> Bool

Bridges Equal.equal(to:) to Equatable.isEqual(to:).

public func isEqual(to: Bool) -> Bool

Returns true if both bits agree. Drives == for Bool.

public func notEqual(to: Self) -> Bool

Default !=: delegates to == so there's a single source of truth.

ImplementsMatchable

Methods

public func matches(Bool) -> Bool

Pattern-match form of isEqual: case true => and case false => dispatch through here.

ImplementsFormattable

Methods

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

Returns 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

Feeds 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 = Bool
type Output = Bool

Methods

public func logicalAnd(() -> Bool) -> Bool

Short-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

Methods

public func logicalOr(() -> Bool) -> Bool

Short-circuiting or: other runs only when self is false.

ImplementsNot

Associated Types

type Output

Methods

public func logicalNot() -> Bool

Bit-flip; not true == false.

ImplementsExpressibleByBoolLiteral

Initializers

init(boolLiteral: lang.i1)

Builds an instance from a boolean literal.

ImplementsBooleanConditional

Methods

public func boolValue() -> lang.i1

Returns the wrapped lang.i1 so if/while can branch on it without a redundant Bool round-trip.

Defined in lang/std/core/bool.ks