Skip to content

Instantly share code, notes, and snippets.

@Emilios1995
Created June 13, 2017 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Emilios1995/b566cdde792a345014387154000432d1 to your computer and use it in GitHub Desktop.
Save Emilios1995/b566cdde792a345014387154000432d1 to your computer and use it in GitHub Desktop.
// updateKeys :: (String -> String) -> Object -> Object
const updateKeys = f =>
R.compose(R.fromPairs, R.map(R.over(R.lensIndex(0), f)), R.toPairs);
// updateKeysWithMap :: Object -> Object -> Object
const updateKeysWithMap = map => updateKeys(k => map[k] || k);
// example:
updateKeysWithMap({ oldKey: "newKey" })({ oldKey: 2 }); // -> { newKey: 2 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment