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);
// trueReference
not
function not<T>(x: T): booleanParameters
| Parameter | Type | Description |
|---|---|---|
x | T | The 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) => booleanParameters
| Parameter | Type | Description |
|---|---|---|
a | (x: T) => unknown | The 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([]);
// falseExample: 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([]); // falseGood to know:
notandnotFnuse JavaScript's standard truthiness evaluation. The value is first converted to a boolean before negation.