Last active
December 18, 2015 19:21
-
-
Save dlmanning/ae9d950420d791811dce to your computer and use it in GitHub Desktop.
dispatch keyed values to keyed functions
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
const branchDispatch = (obj, table, defaultFn) => | |
Object.entries(obj) | |
.map(([key, value]) => | |
table[key] != null | |
? [key, table[key](value)] | |
: typeof defaultFn === 'function' | |
? [key, defaultFn(value)] | |
: [key, undefined] | |
) | |
.reduce((results, [key, value]) => { | |
results[key] = value | |
return results | |
}, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment