Skip to content

Instantly share code, notes, and snippets.

@crshmk
Last active March 7, 2022 21:19
Show Gist options
  • Save crshmk/b87db5c3dc79211ea4adec51310aa4e1 to your computer and use it in GitHub Desktop.
Save crshmk/b87db5c3dc79211ea4adec51310aa4e1 to your computer and use it in GitHub Desktop.
apply a transform to each key in an object
import updateKeys from './updateKeys'
import { map, toLower } from 'ramda'
const x = {
ONE: 1,
TWO: 2
}
const toLowerKeys = updateKeys(toLower)
toLowerKeys(x)
// { one: 1, two: 2 }
const mapToLowerKeys = map(toLowerKeys)
mapToLowerKeys([x, x])
// [ { one: 1, two: 2 }, { one: 1, two: 2 } ]
import {
fromPairs,
lensIndex,
map,
over,
pipe,
toLower,
toPairs
} from 'ramda'
const headLens = lensIndex(0)
const updateKeys = keyTransform =>
pipe(
toPairs,
map(over(headLens, keyTransform)),
fromPairs
)
export default updateKeys
@crshmk
Copy link
Author

crshmk commented Mar 6, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment