Skip to content

bool

Converts any value into a boolean monad (EitherBoolTruthy or EitherBoolFalsy). 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
  ? EitherBoolFalsy<GenericInput>
  : EitherBoolTruthy<GenericInput> | EitherBoolFalsy<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.