Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dispatch keyed values to keyed functions
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