Introduce new lib-function for lists to filter out empty elements#2566
Introduce new lib-function for lists to filter out empty elements#2566SebTM wants to merge 1 commit intonix-community:masterfrom SebTM:lib_lists_notEmpty
Conversation
…lements e.g. for string building
|
I think it's best to avoid introducing this function, I think it is too ambiguous as to what "empty" means in this context. For example, why not remove empty lists as well? And the flatten functionality seems arbitrary. So it seems to me that this function is not actually generally useful but rather intended for a specific use-case. I'm thinking that perhaps a function like removeAny [3 4] [ 1 3 4 3 ]
# => [ 1 ]to match the removeAny = l: builtins.filter (x: ! builtins.elem x l)It wouldn't do any flattening, though, but I think that is an orthogonal functionality. |
|
Hmm, the function/separation outside the module happened after discussion in the above PR, as the "notEmpty"-function comes from "xidlehook" it felt like a more often use-case with the below examples:
The goal with providing this function was to reduce the possible duplicate code and more common handling of these recurring situations, as far as I understand. I understand your point with the naming, we can rename and extend it to also filter empty lists 👍🏻 Thanks for your review and feedback, I appreciate it ⭐ |
|
@SebTM About the flatten, I think that the flattening is so different from the notEmpty [ [ "" 34 ] [] null "s" ]to return I'm not super convinced about the necessity of these functions, though. When it only is empty strings that are removed then I think removes [ "" null ] listOfStuffThe flattening could be done explicitly removes [ "" null ] (flatten listOfStuff)or with a custom function flattenRemoves [ "" null ] listOfStuff |
|
Seems to be not really needed as I could use |
Description
Related to #2314
Moved function needed by this PR because its providing basic/general functionality and therefore should be located in lib
Checklist
Change is backwards compatible.
Code formatted with
./format.Code tested through
nix-shell --pure tests -A run.all.Test cases updated/added. See example.
Commit messages are formatted like
See CONTRIBUTING for more information and recent commit messages for examples.
If this PR adds a new module
Added myself as module maintainer. See example.
Added myself and the module files to
.github/CODEOWNERS.