For use-cases where only part of a document is needed, it would be nice to be able to load and return early.
For an example document:
a:
b:
- x
- y
- z
c:
d: 42
We could partially load, for example:
print(load_part(yaml_text, ".a.c.d")) # -> 42
print(load_part(yaml_text, ".a.b[1]")) # -> "y"
print(load_part(yaml_text, ".a.c")) # -> {'d': 42}
print(load_part(yaml_text, ".a.b")) # -> ['x', 'y', 'z']
print(load_part(yaml_text, ".nonexistent")) # -> None
Advantages (depending on usage of anchors):
- Only materialize values that lie along the requested path.
- Stop as soon as we finished building the value at that path.