ts-cast
Version:
Runtime typechecking
6 lines (5 loc) • 489 B
JavaScript
import { predicateName } from './predicate';
import { withName, joinNames } from '../helpers/names';
export const not = (predicate) => withName((value) => !predicate(value), `not ${predicateName(predicate)}`);
export const or = (...predicates) => withName((value) => predicates.some(p => p(value)), joinNames(predicates.map(predicateName), 'or'));
export const and = (...predicates) => withName((value) => predicates.every(p => p(value)), joinNames(predicates.map(predicateName), 'and'));