I am trying to build a list of names from a list of objects. It works fine, but some of the objects don’t have a name. No problem, I use the default() filter to set those elements of my list to empty strings, like this:
PS: Pointers to USEFUL, COMPLETE examples of how to use rejectattr(), reject() and so on would be useful too. All the examples I have found seem to assume a huge amount of knowledge I don’t have, or are tiny fragments of code…
I am trying to build a list of names from a list of objects. It works fine, but some of the objects don’t have a name. No problem, I use the default() filter to set those elements of my list to empty strings, like this:
map(), select(), and friends return generators; use the list filter (as I’ve done above) to convert it to a list.
PS: Pointers to USEFUL, COMPLETE examples of how to use rejectattr(), reject() and so on would be useful too. All the examples I have found seem to assume a huge amount of knowledge I don’t have, or are tiny fragments of code…
This filter (like most of the others) needs far more complete documentation. It should provide a sample “users” variable, and sample output for the two examples. It should describe clearly what each of the possible parameters to the filter is.
I have no idea whether ANY of the following is correct:
I’m assuming that users is a structured list and that “is_active” and “email” are attributes of the elements of that list, e.g.:
I’m also guessing that “none” is some sort of filter. It’s described as a “test” - where are these tests documented? There is no description of it or link to other documentation, so I really have no idea. It may be selecting users where the email address is the literal string value “none”.
Give the above sample “users” variable, I am guessing that the expected output of the two examples, if assigned to x, would be: