/** * Zips two objects together by their keys, creating an object with * both left and right values for each key. */ export function zipObjects( objLeft?: Partial> | undefined, objRight?: Partial> | undefined, ): Partial> { const allKeys = [...new Set(Object.keys(objLeft || {}).concat(Object.keys(objRight || {})))] return allKeys.reduce>( (acc, key) => { const left = objLeft?.[key] const right = objRight?.[key] return { ...acc, [key]: { left, right }, } }, {}, ) } /** * Returns true if the object has at least one key. */ export function isNotEmpty(obj: A): boolean { return Boolean(Object.keys(obj).length) } /** * Converts an array to a record using the provided key function. */ export function toRecord( arr: ReadonlyArray, key: (obj: A) => string, ): Record { return arr.reduce>((acc, entry) => { const k = key(entry) return { ...acc, [k]: entry, } }, {}) }