returns the value in a nested dict
(m, path, default=None)
| 7 | |
| 8 | |
| 9 | def getin(m, path, default=None): |
| 10 | """returns the value in a nested dict""" |
| 11 | keynotfound = ':com.gooey-project/not-found' |
| 12 | result = reduce(lambda acc, val: acc.get(val, {keynotfound: None}), path, m) |
| 13 | # falsey values like 0 would incorrectly trigger the default to be returned |
| 14 | # so the keynotfound val is used to signify a miss vs just a falesy val |
| 15 | if isinstance(result, dict) and keynotfound in result: |
| 16 | return default |
| 17 | return result |
| 18 | |
| 19 | |
| 20 | def assoc(m, key, val): |
no outgoing calls