-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unions that implement interfaces HAVE fields
- Loading branch information
Showing
4 changed files
with
46 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { ObjMap, ReadOnlyObjMap } from './ObjMap'; | ||
|
||
/** | ||
* Creates an object map from an array of `maps` with the same keys as each `map` | ||
* in `maps` and values generated by running each value of `map` thru `fn`. | ||
*/ | ||
export function mapValues<T, V>( | ||
maps: ReadonlyArray<ReadOnlyObjMap<T>>, | ||
fn: (value: T, key: string) => V, | ||
): ObjMap<V> { | ||
const result = Object.create(null); | ||
|
||
for (const map of maps) { | ||
for (const key of Object.keys(map)) { | ||
result[key] = fn(map[key], key); | ||
} | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters