lib.recursiveCollect: init#331375
Conversation
|
@ofborg test misc |
|
Updated to instead modify the existing |
infinisil
left a comment
There was a problem hiding this comment.
See also #331384 (comment). And similarly to #331384 (review), how about recursiveCollect instead? Then we could also consider renaming collect to attrsRecursiveCollect in the future
This new 'recursiveCollect' function is like 'collect' while additionally descending into lists. This function will be used with user-provided freeform variables - arbitrary combinations of attrset, lists and values - in the upcoming secret management feature. The PR NixOS#328472 shows how it will be used.
| # Type | ||
|
|
||
| ``` | ||
| collect :: (AttrSet -> Bool) -> AttrSet -> [x] |
There was a problem hiding this comment.
| collect :: (AttrSet -> Bool) -> AttrSet -> [x] | |
| collectFromData :: (Any -> Bool) -> Any -> [Any] |
It'd be good to repeat the word data here, matching its use in
(regarding Any, I don't think there's anything useful that can be conveyed in this type without producing lies about its generality)
There was a problem hiding this comment.
(regarding Any, ...
and if that doesn't feel right, maybe that's because a function like this would:
concatFromData :: (Any -> ListOf a) -> Any -> ListOf a
but the predicate function does not produce anything specific beyond a bool, so
:: (Any -> Bool) -> Any -> ListOf a
but that's just
:: (Any -> Bool) -> Any -> ListOf Any
infinisil
left a comment
There was a problem hiding this comment.
Same as #331384 (review) :)
|
|
||
|
|
||
| /** | ||
| Recursively collect sets that verify a given predicate named `pred` from the arbitrary nesting of |
There was a problem hiding this comment.
| Recursively collect sets that verify a given predicate named `pred` from the arbitrary nesting of | |
| Recursively collect values that verify a given predicate named `pred` from the arbitrary nesting of |
| attrs: | ||
| if pred attrs then | ||
| [ attrs ] | ||
| else if isAttrs attrs then | ||
| concatMap (recursiveCollect pred) (attrValues attrs) | ||
| else if isList attrs then | ||
| concatMap (recursiveCollect pred) attrs |
There was a problem hiding this comment.
| attrs: | |
| if pred attrs then | |
| [ attrs ] | |
| else if isAttrs attrs then | |
| concatMap (recursiveCollect pred) (attrValues attrs) | |
| else if isList attrs then | |
| concatMap (recursiveCollect pred) attrs | |
| value: | |
| if pred value then | |
| [ value ] | |
| else if isAttrs value then | |
| concatMap (recursiveCollect pred) (attrValues value) | |
| else if isList value then | |
| concatMap (recursiveCollect pred) value |
| ::: | ||
| */ | ||
| recursiveCollect = | ||
| pred: |
There was a problem hiding this comment.
@roberth Probably pred should also take the path just like #331384 (comment)
Description of changes
Compared to the existing 'collect' function, this one descends into lists too.
This function will be used with user-provided freeform variables - arbitrary combinations of attrset, lists and values - in the upcoming secret management feature. The PR #328472 shows how it will be used.
I purposely created a new function instead of updating the existing 'collect' one because to avoid changing the implementation of such a base function.
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.