lib.attrsets.concatMapAttrs: rewrite for efficiency (#534062)
This commit is contained in:
+14
-9
@@ -5,7 +5,6 @@
|
||||
|
||||
let
|
||||
inherit (builtins) head length;
|
||||
inherit (lib.trivial) mergeAttrs;
|
||||
inherit (lib.strings)
|
||||
concatStringsSep
|
||||
concatMapStringsSep
|
||||
@@ -13,16 +12,18 @@ let
|
||||
sanitizeDerivationName
|
||||
;
|
||||
inherit (lib.lists)
|
||||
filter
|
||||
foldr
|
||||
foldl'
|
||||
all
|
||||
concatLists
|
||||
concatMap
|
||||
elemAt
|
||||
all
|
||||
partition
|
||||
groupBy
|
||||
take
|
||||
filter
|
||||
foldl
|
||||
foldl'
|
||||
foldr
|
||||
groupBy
|
||||
partition
|
||||
reverseList
|
||||
take
|
||||
;
|
||||
in
|
||||
|
||||
@@ -370,7 +371,11 @@ rec {
|
||||
|
||||
:::
|
||||
*/
|
||||
concatMapAttrs = f: v: foldl' mergeAttrs { } (attrValues (mapAttrs f v));
|
||||
concatMapAttrs =
|
||||
f: v:
|
||||
listToAttrs (
|
||||
concatLists (reverseList (mapAttrsToList (name: value: attrsToList (f name value)) v))
|
||||
);
|
||||
|
||||
/**
|
||||
Update or set specific paths of an attribute set.
|
||||
|
||||
@@ -2164,6 +2164,21 @@ runTests {
|
||||
};
|
||||
};
|
||||
|
||||
testConcatMapAttrsDuplicates = {
|
||||
expr =
|
||||
concatMapAttrs
|
||||
(name: value: {
|
||||
final = value;
|
||||
})
|
||||
{
|
||||
a = 1;
|
||||
b = 2;
|
||||
};
|
||||
expected = {
|
||||
final = 2;
|
||||
};
|
||||
};
|
||||
|
||||
testFilterAttrs = {
|
||||
expr = filterAttrs (n: v: n != "a" && (v.hello or false) == true) {
|
||||
a.hello = true;
|
||||
|
||||
Reference in New Issue
Block a user