Skip to main content Link Search Menu Expand Document (external link)

Boolean.ts overview

This module provides utility functions and type class instances for working with the boolean type in TypeScript. It includes functions for basic boolean operations, as well as type class instances for Equivalence and Order.

Since v2.0.0


Exports Grouped by Category


combinators

and

Combines two boolean using AND: self && that.

Example

import * as assert from "node:assert"
import { and } from "effect/Boolean"

assert.deepStrictEqual(and(true, true), true)
assert.deepStrictEqual(and(true, false), false)
assert.deepStrictEqual(and(false, true), false)
assert.deepStrictEqual(and(false, false), false)

Signature

declare const and: { (that: boolean): (self: boolean) => boolean; (self: boolean, that: boolean): boolean }

Source

Since v2.0.0

eqv

Combines two booleans using EQV (aka XNOR): !xor(self, that).

Example

import * as assert from "node:assert"
import { eqv } from "effect/Boolean"

assert.deepStrictEqual(eqv(true, true), true)
assert.deepStrictEqual(eqv(true, false), false)
assert.deepStrictEqual(eqv(false, true), false)
assert.deepStrictEqual(eqv(false, false), true)

Signature

declare const eqv: { (that: boolean): (self: boolean) => boolean; (self: boolean, that: boolean): boolean }

Source

Since v2.0.0

implies

Combines two booleans using an implication: (!self || that).

Example

import * as assert from "node:assert"
import { implies } from "effect/Boolean"

assert.deepStrictEqual(implies(true, true), true)
assert.deepStrictEqual(implies(true, false), false)
assert.deepStrictEqual(implies(false, true), true)
assert.deepStrictEqual(implies(false, false), true)

Signature

declare const implies: { (that: boolean): (self: boolean) => boolean; (self: boolean, that: boolean): boolean }

Source

Since v2.0.0

nand

Combines two boolean using NAND: !(self && that).

Example

import * as assert from "node:assert"
import { nand } from "effect/Boolean"

assert.deepStrictEqual(nand(true, true), false)
assert.deepStrictEqual(nand(true, false), true)
assert.deepStrictEqual(nand(false, true), true)
assert.deepStrictEqual(nand(false, false), true)

Signature

declare const nand: { (that: boolean): (self: boolean) => boolean; (self: boolean, that: boolean): boolean }

Source

Since v2.0.0

nor

Combines two booleans using NOR: !(self || that).

Example

import * as assert from "node:assert"
import { nor } from "effect/Boolean"

assert.deepStrictEqual(nor(true, true), false)
assert.deepStrictEqual(nor(true, false), false)
assert.deepStrictEqual(nor(false, true), false)
assert.deepStrictEqual(nor(false, false), true)

Signature

declare const nor: { (that: boolean): (self: boolean) => boolean; (self: boolean, that: boolean): boolean }

Source

Since v2.0.0

not

Negates the given boolean: !self

Example

import * as assert from "node:assert"
import { not } from "effect/Boolean"

assert.deepStrictEqual(not(true), false)
assert.deepStrictEqual(not(false), true)

Signature

declare const not: (self: boolean) => boolean

Source

Since v2.0.0

or

Combines two boolean using OR: self || that.

Example

import * as assert from "node:assert"
import { or } from "effect/Boolean"

assert.deepStrictEqual(or(true, true), true)
assert.deepStrictEqual(or(true, false), true)
assert.deepStrictEqual(or(false, true), true)
assert.deepStrictEqual(or(false, false), false)

Signature

declare const or: { (that: boolean): (self: boolean) => boolean; (self: boolean, that: boolean): boolean }

Source

Since v2.0.0

xor

Combines two booleans using XOR: (!self && that) || (self && !that).

Example

import * as assert from "node:assert"
import { xor } from "effect/Boolean"

assert.deepStrictEqual(xor(true, true), false)
assert.deepStrictEqual(xor(true, false), true)
assert.deepStrictEqual(xor(false, true), true)
assert.deepStrictEqual(xor(false, false), false)

Signature

declare const xor: { (that: boolean): (self: boolean) => boolean; (self: boolean, that: boolean): boolean }

Source

Since v2.0.0

guards

isBoolean

Tests if a value is a boolean.

Example

import * as assert from "node:assert"
import { isBoolean } from "effect/Boolean"

assert.deepStrictEqual(isBoolean(true), true)
assert.deepStrictEqual(isBoolean("true"), false)

Signature

declare const isBoolean: (input: unknown) => input is boolean

Source

Since v2.0.0

instances

Equivalence

Signature

declare const Equivalence: equivalence.Equivalence<boolean>

Source

Since v2.0.0

Order

Signature

declare const Order: order.Order<boolean>

Source

Since v2.0.0

pattern matching

match

This function returns the result of either of the given functions depending on the value of the boolean parameter. It is useful when you have to run one of two functions depending on the boolean value.

Example

import * as assert from "node:assert"
import { Boolean } from "effect"

assert.deepStrictEqual(Boolean.match(true, { onFalse: () => "It's false!", onTrue: () => "It's true!" }), "It's true!")

Signature

declare const match: {
  <A, B = A>(options: { readonly onFalse: LazyArg<A>; readonly onTrue: LazyArg<B> }): (value: boolean) => A | B
  <A, B>(value: boolean, options: { readonly onFalse: LazyArg<A>; readonly onTrue: LazyArg<B> }): A | B
}

Source

Since v2.0.0

utils

every

This utility function is used to check if all the elements in a collection of boolean values are true.

Example

import * as assert from "node:assert"
import { every } from "effect/Boolean"

assert.deepStrictEqual(every([true, true, true]), true)
assert.deepStrictEqual(every([true, false, true]), false)

Signature

declare const every: (collection: Iterable<boolean>) => boolean

Source

Since v2.0.0

some

This utility function is used to check if at least one of the elements in a collection of boolean values is true.

Example

import * as assert from "node:assert"
import { some } from "effect/Boolean"

assert.deepStrictEqual(some([true, false, true]), true)
assert.deepStrictEqual(some([false, false, false]), false)

Signature

declare const some: (collection: Iterable<boolean>) => boolean

Source

Since v2.0.0