Skip to content

Instantly share code, notes, and snippets.

@obaranovskyi
Created December 22, 2021 04:47
Show Gist options
  • Save obaranovskyi/71e9ce60282107bacce01a72e0a3ad5a to your computer and use it in GitHub Desktop.
Save obaranovskyi/71e9ce60282107bacce01a72e0a3ad5a to your computer and use it in GitHub Desktop.
type PredicateFn = (value: any, index?: number) => boolean;
type ProjectionFn = (value: any, index?: number) => any;
function or(...predicates: PredicateFn[]): PredicateFn {
return (value) => predicates.some((predicate) => predicate(value));
}
function and(...predicates: PredicateFn[]): PredicateFn {
return (value) => predicates.every((predicate) => predicate(value));
}
function not(...predicates: PredicateFn[]): PredicateFn {
return (value) => predicates.every((predicate) => !predicate(value));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment