lol
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/attrsets: add concatMapAttrs

figsoda f993f8a1 4536ebad

+38 -2
+20 -1
lib/attrsets.nix
··· 3 3 4 4 let 5 5 inherit (builtins) head tail length; 6 - inherit (lib.trivial) id; 6 + inherit (lib.trivial) flip id mergeAttrs pipe; 7 7 inherit (lib.strings) concatStringsSep concatMapStringsSep escapeNixIdentifier sanitizeDerivationName; 8 8 inherit (lib.lists) foldr foldl' concatMap concatLists elemAt all partition groupBy take foldl; 9 9 in ··· 76 76 getAttrFromPath = attrPath: 77 77 let errorMsg = "cannot find attribute `" + concatStringsSep "." attrPath + "'"; 78 78 in attrByPath attrPath (abort errorMsg); 79 + 80 + /* Map each attribute in the given set and merge them into a new attribute set. 81 + 82 + Type: 83 + concatMapAttrs :: 84 + (String -> a -> AttrSet) 85 + -> AttrSet 86 + -> AttrSet 87 + 88 + Example: 89 + concatMapAttrs 90 + (name: value: { 91 + ${name} = value; 92 + ${name + value} = value; 93 + }) 94 + { x = "a"; y = "b"; } 95 + => { x = "a"; xa = "a"; y = "b"; yb = "b"; } 96 + */ 97 + concatMapAttrs = f: flip pipe [ (mapAttrs f) attrValues (foldl' mergeAttrs { }) ]; 79 98 80 99 81 100 /* Update or set specific paths of an attribute set.
+1 -1
lib/default.nix
··· 78 78 inherit (self.attrsets) attrByPath hasAttrByPath setAttrByPath 79 79 getAttrFromPath attrVals attrValues getAttrs catAttrs filterAttrs 80 80 filterAttrsRecursive foldAttrs collect nameValuePair mapAttrs 81 - mapAttrs' mapAttrsToList mapAttrsRecursive mapAttrsRecursiveCond 81 + mapAttrs' mapAttrsToList concatMapAttrs mapAttrsRecursive mapAttrsRecursiveCond 82 82 genAttrs isDerivation toDerivation optionalAttrs 83 83 zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil 84 84 recursiveUpdate matchAttrs overrideExisting showAttrPath getOutput getBin
+17
lib/tests/misc.nix
··· 478 478 479 479 # ATTRSETS 480 480 481 + testConcatMapAttrs = { 482 + expr = concatMapAttrs 483 + (name: value: { 484 + ${name} = value; 485 + ${name + value} = value; 486 + }) 487 + { 488 + foo = "bar"; 489 + foobar = "baz"; 490 + }; 491 + expected = { 492 + foo = "bar"; 493 + foobar = "baz"; 494 + foobarbaz = "baz"; 495 + }; 496 + }; 497 + 481 498 # code from the example 482 499 testRecursiveUpdateUntil = { 483 500 expr = recursiveUpdateUntil (path: l: r: path == ["foo"]) {