Open kurka opened 3 years ago
It depends somewhat on whether you want to access all fields, or named subset.
For all fields, the lambda t: tuple(t.values())
method is the most appropriate (it could also be rewritten as Invoke(tuple).specs(T.values())
).
If you want to access a specific, static set of fields however, then you could use the new Fill
mode:
glom(target, [Fill((T['a'], T['b']))])
# or
glom(target, [Fill((Path('a'), Path('b')))])
Although truth be told, the way Fill
actually works is rather different from what I understood it to be from the docs. My understanding was that this would work for what you're trying to do, but it doesn't:
# not the expected result
glom(target, [Fill(('a', 'b'))])
>>> [('a', 'b'), ('a', 'b')]
Say I have the following data structure:
I want to create a spec that access both fields
'a'
and'b'
at the same level, but instead of storing their values on a dictionary, I want to store on a tuple, so to achieve:For example:
This does not work, as 'b' is interpreted as the spec of the next level, and not as a 'parallel' access at the same level.
I was able to obtain the desired result with:
But I wonder if there is a more appropriate way? Thanks in advance!