Skip to content

Instantly share code, notes, and snippets.

@davidchase
Last active November 11, 2016 16:20
Show Gist options
  • Save davidchase/31a9e5722a657be7592ca871e214839d to your computer and use it in GitHub Desktop.
Save davidchase/31a9e5722a657be7592ca871e214839d to your computer and use it in GitHub Desktop.
import {curryN, has, values, is} from 'ramda'
// given a error object from a third party source
// which may not guarantee structure
// quick search via recursion to find property
const err = {
system: {
status: {
err: {
response: 'boom',
id: 12
},
code: 400
}
}
}
// does not have system parent
const err2 = {
status: {
err: {
response: 'boom',
id: 12
},
code: 400
}
}
const findProp = curryN(2, (prop, obj) => has(prop, obj) ? obj[prop] : values(obj).reduce((acc, value) => is(Object, value) ? findProp(prop, value) : acc, {}))
findProp('response', err) // => 'boom'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment