erratic-gate/src/common/lang/record/map.ts
2020-04-13 17:45:44 +03:00

11 lines
307 B
TypeScript

// Like Array.map but for records
export const mapRecord = <T extends keyof object, A, B>(
record: Record<T, A>,
mapper: (a: A) => B
): Record<T, B> =>
Object.fromEntries(
Object.entries(record).map(([key, value]: [T, A]) => [
key,
mapper(value)
])
)