Skip to content

Instantly share code, notes, and snippets.

@jonaswide
Last active January 24, 2018 12:40
Show Gist options
  • Save jonaswide/70a945a8e7240d0537a23f241fb1a64f to your computer and use it in GitHub Desktop.
Save jonaswide/70a945a8e7240d0537a23f241fb1a64f to your computer and use it in GitHub Desktop.
Currying utility to add property to object
export const addPropToObj = key => obj => val => ({ ...obj, [key]: val })
// Example
const firstObj = { a: 1, b: 2, c: 3 }
addPropToObj("d", firstObj, 4) // { a: 1, b: 2, c: 3, d: 4 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment