import { difference, equals } from 'remeda' import { Mapper } from './Mapper' import { GetUid } from './zod' export type IsEqual = (a: U) => (b: U) => boolean export const isEqualBy = (mapper: Mapper) => (a: In, b: In) => isEqualByD(a, b, mapper) /** * DC = Deep Curried */ export const isEqualDC = (a: U) => (b: U) => equals(a, b) /** * SC = Shallow Curried */ export const isEqualSC = equals /** * D = Deep */ export const isEqualByD = (a: U, b: U, mapper: Mapper) => equals(mapper(a), mapper(b)) /** * DC = Deep Curried */ export const isEqualByDC = (mapper: Mapper) => (a: U) => (b: U) => isEqualByD(a, b, mapper) export function isSubsetOf(set: T[], subset: T[]) { return difference(set, subset).length === 0 } // export function mergeWithArrays(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2 { // return mergeWith(object, source1, source2, function (a, b) { // if (isArray(a) && isArray(b)) { // return b.concat(a) // } // }) // } export const notInBy = (getUid: GetUid) => (elements: Elem[]) => (element: Elem) => { return !elements.find(el => isEqualByD(el, element, getUid)) } /** * Doesn't allow undefined values */ export const identityStrict = (value: T) => value