import { ById } from '@app/models/state' import merge from 'lodash.merge' export function reduceById(collection: T[]): ById { return collection.reduce((acc, value) => { acc[value.id] = value return acc }, {} as ById) } export function mergeById(object: T, source: T): void { merge(object, source) } export function mapById(object: ById, ids: string[]): T[] { return ids.map(id => object[id]).filter(a => a !== undefined) } export function mapId(entities: { id: string }[]): string[] { return entities.map(e => e.id) }