Last active
October 31, 2022 10:58
-
-
Save crshmk/b17653ebfe6326264e888297028ef483 to your computer and use it in GitHub Desktop.
Apply a transform function to object keys, recursively
This file contains hidden or 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
import { fromPairs, is, map, pipe, toPairs } from 'ramda' | |
const isObject = is(Object) | |
const transformKey = transform => | |
([k, v]) => !isObject(v) ? [transform(k), v] : | |
[transform(k), mapKeys(transform)(v)] | |
const mapKeys = transform => | |
pipe( | |
toPairs, | |
map(transformKey(transform)), | |
fromPairs | |
) | |
export default mapKeys |
Author
crshmk
commented
Oct 31, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment