2023-03-20 22:35:11 +01:00
|
|
|
{ lib, ... }:
|
|
|
|
|
rec {
|
|
|
|
|
# attrsToList
|
2024-08-20 22:58:24 +02:00
|
|
|
attrsToList = attrs: lib.mapAttrsToList (name: value: { inherit name value; }) attrs;
|
2023-03-20 22:35:11 +01:00
|
|
|
|
|
|
|
|
# mapFilterAttrs ::
|
|
|
|
|
# (name -> value -> bool)
|
|
|
|
|
# (name -> value -> { name = any; value = any; })
|
|
|
|
|
# attrs
|
2024-08-20 22:58:24 +02:00
|
|
|
mapFilterAttrs =
|
|
|
|
|
pred: f: attrs:
|
|
|
|
|
lib.filterAttrs pred (lib.mapAttrs' f attrs);
|
2023-03-20 22:35:11 +01:00
|
|
|
|
|
|
|
|
# Generate an attribute set by mapping a function over a list of values.
|
2024-08-20 22:58:24 +02:00
|
|
|
genAttrs' = values: f: lib.listToAttrs (map f values);
|
2023-03-20 22:35:11 +01:00
|
|
|
|
|
|
|
|
# anyAttrs :: (name -> value -> bool) attrs
|
2024-08-20 22:58:24 +02:00
|
|
|
anyAttrs = pred: attrs: lib.any (attr: pred attr.name attr.value) (attrsToList attrs);
|
2023-03-20 22:35:11 +01:00
|
|
|
|
|
|
|
|
# countAttrs :: (name -> value -> bool) attrs
|
2024-08-20 22:58:24 +02:00
|
|
|
countAttrs = pred: attrs: lib.count (attr: pred attr.name attr.value) (attrsToList attrs);
|
2023-03-20 22:35:11 +01:00
|
|
|
}
|