Standard Toolkit
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) => boolean

Parameters

ParameterTypeDescription
aAThe 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 value
  • B - The type of the second input value

nandFn

function nandFn<T, A>(
  a: (x: T) => A
): <B>(b: (y: T) => B) => (c: T) => boolean

Parameters

ParameterTypeDescription
a(x: T) => AThe 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 functions
  • A - The return type of the first function
  • B - 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);   // false

Good 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.

  • and - Logical conjunction (&&)
  • nor - Logical NOR (!(a || b))
  • not - Logical negation (!)
  • xor - Logical exclusive OR

On this page