old
1# https://github.com/NixOS/nixpkgs/blob/master/lib/attrsets.nix
2{lib, ...}: {
3 # Generate an attribute set from a list.
4 #
5 # lib.genAttrs [ "foo" "bar" ] (name: "x_" + name)
6 # => { foo = "x_foo"; bar = "x_bar"; }
7 listToAttrs = lib.genAttrs;
8
9 # Update only the values of the given attribute set.
10 #
11 # mapAttrs
12 # (name: value: ("bar-" + value))
13 # { x = "a"; y = "b"; }
14 # => { x = "bar-a"; y = "bar-b"; }
15 inherit (lib.attrsets) mapAttrs;
16
17 # Update both the names and values of the given attribute set.
18 #
19 # mapAttrs'
20 # (name: value: nameValuePair ("foo_" + name) ("bar-" + value))
21 # { x = "a"; y = "b"; }
22 # => { foo_x = "bar-a"; foo_y = "bar-b"; }
23 inherit (lib.attrsets) mapAttrs';
24
25 # Merge a list of attribute sets into one. smilar to the operator `a // b`, but for a list of attribute sets.
26 # NOTE: the later attribute set overrides the former one!
27 #
28 # mergeAttrsList
29 # [ { x = "a"; y = "b"; } { x = "c"; z = "d"; } { g = "e"; } ]
30 # => { x = "c"; y = "b"; z = "d"; g = "e"; }
31 inherit (lib.attrsets) mergeAttrsList;
32
33 # Generate a string from an attribute set.
34 #
35 # attrsets.foldlAttrs
36 # (acc: name: value: acc + "\nexport ${name}=${value}")
37 # "# A shell script"
38 # { x = "a"; y = "b"; }
39 # =>
40 # ```
41 # # A shell script
42 # export x=a
43 # export y=b
44 # ````
45 inherit (lib.attrsets) foldlAttrs;
46}