Created
September 13, 2022 22:15
-
-
Save tjconcept/96bd527afd601de606889599862be07d to your computer and use it in GitHub Desktop.
"join" for objects (Promise.props)
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
export default function using(hash, fn) { | |
if (typeof fn !== 'function') { | |
throw new Error('Missing expected function argument') | |
} | |
return Promise.all(Object.values(hash)).then((values) => | |
fn( | |
Object.fromEntries( | |
Object.keys(hash).map((key, idx) => [key, values[idx]]) | |
) | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment