import { Eq } from 'fp-ts/lib/Eq' import { isNotUndefined, isUndefined } from './typeGuards' // Like Record.isSubrecord but works for Partial> export const hasPartialEquals = ( keys: Iterable, E: Eq, ) => (d1: Partial>, d2: Partial>): boolean => { for (const k of keys) { const x = d1[k] const y = d2[k] if (isNotUndefined(x) && isNotUndefined(y)) { // X && Y isNot undefined, so run thru Eq. if (!E.equals(x, y)) { return false } // Unless both x,y is undefined, it's `false` // because it'll mean one is defined and one is undefined. } else if (!(isUndefined(x) && isUndefined(y))) { return false } } return true }