export function keyBy( arr: readonly T[], key: K, ): Map { return arr.reduce((acc, cur) => { acc.set(cur[key], cur) return acc }, new Map()) } export const mapDefined = ( arr: T[], fn: (obj: T) => S | undefined, ): S[] => { const output: S[] = [] for (const item of arr) { const val = fn(item) if (val !== undefined) { output.push(val) } } return output }