predicates

논리 연산자를 대체할 수 있는 함수

type Predicate<T extends any[]> = (...args: T) => boolean;

type PredicateOperator = <T extends any[]>(
  predicate: Predicate<T>
) => Predicate<T>;

type PredicateCombiner = <T extends any[]>(
  ...predicates: Predicate<T>[]
) => Predicate<T>;

not

/**
 * @example
 * const isOdd = not(isEven);
 * isOdd(x) === !isEven(x); // true
 *
 */

const not: PredicateOperator = 
  (predicate) =>
  (...inputs) =>
    !predicate(...inputs);

all

any

none

xor

Last updated