Packages@accelint/coreLogical
nand
Logical NAND (NOT AND) for values and function results
Usage
import { nand, nandFn } from '@accelint/core';
// Value-based NAND
nand(true)(false);
// true
nand(true)(true);
// false
// Function-based NAND
const isPositive = (x: number) => x > 0;
const isLessThan10 = (x: number) => x < 10;
nandFn(isPositive)(isLessThan10)(5);
// false (both true, so NAND is false)
nandFn(isPositive)(isLessThan10)(15);
// true (second is false, so NAND is true)Reference
nand
function nand<A>(a: A): <B>(b: B) => booleanParameters
| Parameter | Type | Description |
|---|---|---|
a | A | The first value to compare |
Returns
Returns a curried function that accepts a second value and returns true if not both values are truthy, false if both are truthy.
Type Parameters
A- The type of the first input valueB- The type of the second input value
nandFn
function nandFn<T, A>(
a: (x: T) => A
): <B>(b: (y: T) => B) => (c: T) => booleanParameters
| Parameter | Type | Description |
|---|---|---|
a | (x: T) => A | The first function to evaluate |
Returns
Returns a curried function that accepts a second function, then accepts a value to pass to both functions, returning true if not both function results are truthy, false if both are truthy.
Type Parameters
T- The type of the input value passed to both functionsA- The return type of the first functionB- The return type of the second function
Examples
Example: Validation constraints
import { nand } from '@accelint/core';
// User cannot have both admin AND guest roles simultaneously
const isAdmin = true;
const isGuest = false;
const rolesValid = nand(isAdmin)(isGuest);
// true (not both are true)Example: Exclusion logic with predicates
import { nandFn } from '@accelint/core';
const isWeekend = (date: Date) => [0, 6].includes(date.getDay());
const isHoliday = (date: Date) => holidays.includes(date.toDateString());
// Business day logic: not (weekend AND holiday)
const canSchedule = nandFn(isWeekend)(isHoliday);
canSchedule(new Date('2024-07-04')); // Thursday, holiday
// true (only one condition is true)Example: NAND truth table
import { nand } from '@accelint/core';
// NAND truth table (opposite of AND)
nand(false)(false); // true
nand(false)(true); // true
nand(true)(false); // true
nand(true)(true); // falseGood to know: NAND is the logical inverse of AND. It's functionally complete—all other logical operations can be constructed from NAND alone. This implementation uses
not(and(a)(b))internally.