Open kurka opened 3 years ago
lists ignore everything after the first element -- if you want them to be executed one after the other you'll need a tuple in the list
glom(target, [(T.as, [T.v])])
then you'll probably want a flatten at the end so you don't get [[1, 2, 3], [4, 5, 6]
but [1, 2, 3, 4, 5, 6]
glom(target, ([(T.as, [T.v])], Flatten()))
Many thanks, @kurtbrose, that's exactly the solution I needed!
But I was a bit confused with the statement "lists ignore everything after the first element". Why is that the case? Is this documented somewhere?
I indeed noticed that I could write any invalid expression in the second element of the list and it wouldn't have any effect... Shouldn't at least a warning be raised if a multi element list is passed in a spec?
I am trying to get all elements from nested lists of classes, using glom.
I have the following definitions:
that is,
U
stores a list ofA
classes, each storing a value (v
) as attribute.I am trying to list all values for the nested classes
A
with the expression:However, instead of a list of lists of
v
, I get:It seems that the second call for
T
(T.v
) has no effect, and what is returned is the value of the firstT
call (T.as
). Is this a bug, or something expected?If that's expected, what is the right way to access nested class objects, and have different contexts for
T
on a glom spec?