Standard Toolkit
Packages@accelint/coreLogical

not

Logical negation (!) for values and function results

Usage

import { not, notFn } from '@accelint/core';

// Value negation
not(true);
// false

not(0);
// true

// Function result negation
const isEven = (x: number) => x % 2 === 0;
const isOdd = notFn(isEven);

isOdd(4);
// false

isOdd(5);
// true

Reference

not

function not<T>(x: T): boolean

Parameters

ParameterTypeDescription
xTThe value to negate

Returns

Returns the negated boolean value of the input.

Type Parameters

  • T - The type of the input value

notFn

function notFn<T>(a: (x: T) => unknown): (b: T) => boolean

Parameters

ParameterTypeDescription
a(x: T) => unknownThe function whose result to negate

Returns

Returns a function that accepts a value, passes it to the given function, and returns the negated boolean result.

Type Parameters

  • T - The type of the input value passed to the function

Examples

Example: Creating inverse predicates

import { notFn } from '@accelint/core';

const isEmpty = (arr: unknown[]) => arr.length === 0;
const hasItems = notFn(isEmpty);

hasItems([1, 2, 3]);
// true

hasItems([]);
// false

Example: Filtering with negation

import { notFn, filter } from '@accelint/core';

const isNull = (x: unknown) => x === null;
const notNull = notFn(isNull);

filter(notNull)([1, null, 2, null, 3]);
// [1, 2, 3]

Example: Boolean conversion

import { not } from '@accelint/core';

// All falsy values become true
not(0);        // true
not('');       // true
not(null);     // true
not(undefined);// true
not(false);    // true

// All truthy values become false
not(1);        // false
not('hello');  // false
not({});       // false
not([]);       // false

Good to know: not and notFn use JavaScript's standard truthiness evaluation. The value is first converted to a boolean before negation.

  • and - Logical conjunction (&&)
  • or - Logical disjunction (||)
  • nand - Logical NAND (!(a && b))
  • nor - Logical NOR (!(a || b))

On this page