MCPcopy
hub / github.com/chriskiehl/Gooey / getin

Function getin

gooey/util/functional.py:9–17  ·  view source on GitHub ↗

returns the value in a nested dict

(m, path, default=None)

Source from the content-addressed store, hash-verified

7
8
9def 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
20def assoc(m, key, val):

Calls

no outgoing calls