Skip to content

Bool

const Bool: object

Defined in: Data/Bool.ts:85

all: (booleans) => boolean

N-ary AND aggregation across an array of booleans. Returns true if every boolean is true, or for an empty array (vacuous truth). Short-circuits on the first false.

readonly boolean[]

boolean

Bool.all([true, true, true]);  // true
Bool.all([true, false, true]); // false
Bool.all([]);                  // true

and: (that) => (self) => boolean

Logical AND combinator. Returns true only if both self and that are true.

Data-last: pipe(self, Bool.and(that)).

boolean

(self) => boolean

pipe(true, Bool.and(true));  // true
pipe(true, Bool.and(false)); // false

andLazy: (that) => (self) => boolean

Lazy logical AND combinator. If self is false, the that computation is never evaluated.

Data-last: pipe(self, Bool.andLazy(that)).

() => boolean

(self) => boolean

pipe(
  isCached,
  Bool.andLazy(() => checkPermissions())
);

any: (booleans) => boolean

N-ary OR aggregation across an array of booleans. Returns true if at least one boolean is true. Returns false for an empty array. Short-circuits on the first true.

readonly boolean[]

boolean

Bool.any([false, true, false]); // true
Bool.any([false, false]);       // false
Bool.any([]);                   // false

fold: <A, B>(onFalse, onTrue) => (b) => A | B

Catamorphism for boolean: evaluates onFalse() when false and onTrue() when true.

Positional ordering: onFalse first, onTrue second. Aligned with Result.fold(onErr, onOk) and Maybe.fold(onNone, onSome).

A

B

() => A

() => B

(b) => A | B

pipe(
  isDarkMode,
  Bool.fold(
    () => "light-theme",
    () => "dark-theme"
  )
);

from: object

number: (n) => Maybe<boolean> = fromNumber

Converts a number into a Maybe<boolean>. Returns Some(true) for 1, Some(false) for 0, and None for any other number.

number

Maybe<boolean>

Bool.from.number(1);  // Some(true)
Bool.from.number(0);  // Some(false)
Bool.from.number(42); // None

string: (s) => Maybe<boolean> = fromString

Parses a string into a Maybe<boolean>. Returns Some(true) for "true", Some(false) for "false" (case-insensitive & trimmed), and None for any other string.

string

Maybe<boolean>

Bool.from.string("true");  // Some(true)
Bool.from.string("FALSE"); // Some(false)
Bool.from.string("yes");   // None

truthy: (value) => boolean = fromTruthy

Coerces any unknown value into a boolean via standard JS Boolean(value).

unknown

boolean

Bool.from.truthy("hello"); // true
Bool.from.truthy(0);       // false

is: object

boolean: (u) => u is boolean = isBoolean

Type guard — checks if a value is a primitive boolean.

unknown

u is boolean

Bool.is.boolean(true);      // true
Bool.is.boolean(false);     // true
Bool.is.boolean("true");    // false
Bool.is.boolean(null);      // false

false: (u) => u is false = isFalse

Narrowing guard — checks if a value is strictly false.

unknown

u is false

Bool.is.false(false); // true
Bool.is.false(true);  // false

falsy: (u) => u is false | “” | 0 | 0n | null | undefined = isFalsy

Type guard — checks if a value is falsy (false, 0, 0n, "", null, undefined, or NaN).

unknown

u is false | “” | 0 | 0n | null | undefined

Bool.is.falsy("");        // true
Bool.is.falsy(null);      // true
Bool.is.falsy("content"); // false

true: (u) => u is true = isTrue

Narrowing guard — checks if a value is strictly true.

unknown

u is true

Bool.is.true(true);  // true
Bool.is.true(false); // false

truthy: <T>(u) => u is Exclude<T, false | “” | 0 | 0n | null | undefined> = isTruthy

Type guard — checks if a value is truthy (not false, 0, 0n, "", null, undefined, or NaN).

T

T

u is Exclude<T, false | “” | 0 | 0n | null | undefined>

Bool.is.truthy("hello"); // true
Bool.is.truthy(42);      // true
Bool.is.truthy(0);       // false
Bool.is.truthy(null);    // false

match: <A, B>(cases) => (b) => A | B

Pattern matching on boolean using named cases { true, false }.

A

B

BoolMatchCases<A, B>

(b) => A | B

pipe(
  isEnabled,
  Bool.match({
    true: () => "Feature Active",
    false: () => "Feature Disabled",
  })
);

not: (b) => boolean

Unary boolean negation: inverts the given boolean value.

boolean

boolean

Bool.not(true);  // false
Bool.not(false); // true

or: (that) => (self) => boolean

Logical OR combinator. Returns true if either self or that is true.

Data-last: pipe(self, Bool.or(that)).

boolean

(self) => boolean

pipe(false, Bool.or(true));  // true
pipe(false, Bool.or(false)); // false

orLazy: (that) => (self) => boolean

Lazy logical OR combinator. If self is true, the that computation is never evaluated.

Data-last: pipe(self, Bool.orLazy(that)).

() => boolean

(self) => boolean

pipe(
  isAdmin,
  Bool.orLazy(() => hasAccess(userId))
);

to: object

Maybe: <A>(onTrue) => (b) => Maybe<A> = toMaybe

Lifts a boolean condition into a Maybe. Returns Some(onTrue()) when true, and None when false.

A

() => A

(b) => Maybe<A>

pipe(
  user.isVerified,
  Bool.to.Maybe(() => user.profile)
); // Some(profile) or None

number: (b) => 0 | 1 = toNumber

Converts a boolean to numeric 1 or 0.

boolean

0 | 1

Bool.to.number(true);  // 1
Bool.to.number(false); // 0

Result: <E, A>(onErr, onOk) => (b) => Result<E, A> = toResult

Lifts a boolean condition into a Result. Returns Ok(onOk()) when true, and Err(onErr()) when false.

E

A

() => E

() => A

(b) => Result<E, A>

pipe(
  hasPermission,
  Bool.to.Result(
    () => "Permission denied",
    () => sessionData
  )
); // Ok(sessionData) or Err("Permission denied")

string: (b) => "false" | "true" = toString

Converts a boolean to literal string "true" or "false".

boolean

"false" | "true"

Bool.to.string(true);  // "true"
Bool.to.string(false); // "false"

xor: (that) => (self) => boolean

Logical XOR (exclusive OR) combinator. Returns true if exactly one of self and that is true.

Data-last: pipe(self, Bool.xor(that)).

boolean

(self) => boolean

pipe(true, Bool.xor(false)); // true
pipe(true, Bool.xor(true));  // false