nix-config/lib/attrs.nix

22 lines
560 B
Nix
Raw Normal View History

{ lib, ... }:
let
2021-04-03 19:12:34 +02:00
inherit (lib) filterAttrs listToAttrs mapAttrs';
in
{
2021-04-03 19:12:34 +02:00
# Filter a generated set of attrs using a predicate function.
#
# mapFilterAttrs ::
# (name -> value -> bool)
# (name -> value -> { name = any; value = any; })
# attrs
mapFilterAttrs = pred: f: attrs: filterAttrs pred (mapAttrs' f attrs);
2021-04-03 19:11:55 +02:00
2021-04-03 19:12:34 +02:00
# Generate an attribute set by mapping a function over a list of values.
#
# genAttrs' ::
# [ values ]
# (value -> { name = any; value = any; })
# attrs
2021-04-03 19:11:55 +02:00
genAttrs' = values: f: listToAttrs (map f values);
}