Created
March 6, 2020 06:12
-
-
Save guhou/8199a7dc2f580e420acd811d143ea6a4 to your computer and use it in GitHub Desktop.
What is the name of this `unSequence` function?
This file contains hidden or 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
export function sequence<T>( | |
map: Map<string, Promise<T>> | |
): Promise<Map<string, T>> { | |
return Promise.all( | |
Array.from(map, ([key, promisedValue]) => | |
promisedValue.then<[string, T]>(value => [key, value]) | |
) | |
).then((entries) => new Map(entries)); | |
} | |
export function unSequence<T>( | |
promisedMap: Promise<Map<string, T>>, | |
keys: string[] | |
): Map<string, Promise<T | undefined>> { | |
return new Map( | |
keys.map(key => | |
[key, promisedMap.then(map => map.get(key))] | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment