utils.ts 491 B

1234567891011121314
  1. /**
  2. * Takes a predicate function and returns a negated version.
  3. */
  4. export function not(predicate: (...args: any[]) => boolean) {
  5. return (...args: any[]) => !predicate(...args);
  6. }
  7. /**
  8. * Returns a predicate function which returns true if the item is found in the set,
  9. * as determined by a === equality check on the given compareBy property.
  10. */
  11. export function foundIn<T>(set: Array<T>, compareBy: keyof T) {
  12. return (item: T) => set.some(t => t[compareBy] === item[compareBy]);
  13. }