Skip to content

bool ​

Converts any value into a boolean monad (BoolTruthy or BoolFalsy). Handy to keep track of the test while benefiting from the whenIsBoolTruthy/whenIsBoolFalsy helpers.

Interactive example ​

Syntax ​

typescript
function bool<
	const GenericInput extends unknown = undefined
>(
  input: GenericInput
): GenericInput extends BoolFalsyValue
  ? BoolFalsy<GenericInput>
  : BoolTruthy<GenericInput> | BoolFalsy<BoolFalsyValue>;

Parameters ​

  • input: Value to interpret. Standard falsy values ("", 0, false, null, undefined) produce a Left.

Return value ​

An Either: Right<"bool"> when the value is truthy, Left<"bool"> otherwise. Typing preserves the original value.

See also ​

Released under the MIT license.