summaryrefslogtreecommitdiffstats
path: root/lib/attrsets.nix
blob: 9d0988023054afa5d16fd7a6280ba68768b747f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{lib}: let
  inherit (builtins) listToAttrs;
in {
  /**
  Map over a list and convert the result to an attribute set.

  # Type

  ```
  mapListToAttrs :: (a -> { name :: String; value :: b }) -> [a] -> AttrSet
  ```

  # Arguments

  - `f`: Function mapping each list element to a `{ name; value }` pair.
  - `list`: The list to map over.

  # Example

  ```nix
  mapListToAttrs (x: { name = x; value = x; }) ["a" "b"]
  => { a = "a"; b = "b"; }
  ```
  */
  mapListToAttrs = f: list: listToAttrs (map f list);
}