Skip to content

Bool

const Bool: object

Defined in: Data/Bool.ts:81

all: (conditions) => 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.any to check if at least one boolean is true.

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

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

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

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

boolean

(condition) => boolean

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

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

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

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

() => boolean

(condition) => boolean

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

any: (conditions) => 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.all to check if all booleans are true.

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

from: object

Parsers and converters from external values to boolean.

number: (value) => 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: (text) => 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

Predicates and type guards for boolean values.

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

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

unknown

value is boolean

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

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

Narrowing guard — checks if a value is strictly false.

unknown

value is false

Bool.is.true to check if a value is strictly true.

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

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

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

unknown

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

Bool.is.truthy to check if a value is truthy.

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

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

Narrowing guard — checks if a value is strictly true.

unknown

value is true

Bool.is.false to check if a value is strictly false.

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

truthy: <T>(value) => value 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

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

Bool.is.falsy to check if a value is falsy.

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

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

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

A

B

() => B

() => A

(condition) => A | B

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

not: (condition) => boolean

Unary boolean negation: inverts the given boolean value.

boolean

boolean

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

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

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

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

boolean

(condition) => boolean

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

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

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

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

() => boolean

(condition) => boolean

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

to: object

Converters from boolean conditions into strings, Maybe, or Result.

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

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

A

() => A

(condition) => Maybe<A>

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

number: (condition) => 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) => (condition) => 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

(condition) => Result<E, A>

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

string: (condition) => "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) => (condition) => boolean

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

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

boolean

(condition) => boolean

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