How can one include field-specific defaults in glom's output?
For example, I can include "constants" like this:
from glom import Spec, Literal
extract = Spec({'A': 'a', 'B': Literal(42)}).glom
assert extract({'a': 'life'}) == {'A': 'life', 'B': 42}
But how do I specify that 'B' should point to 42 only if 'B' is not in the input? Stepping out of glom I can do this:
from glom import Spec
extract = lambda d: dict(Spec({'A': 'a'}).glom(d), B=d.get('B', 42))
assert extract({'a': 'life'}) == {'A': 'life', 'B': 42}
assert extract({'a': 'life', 'B': 'is short'}) == {'A': 'life', 'B': 'is short'}
Surely, there a glommier way to do this.