Working on modularizing stuff

This commit is contained in:
Chris Kruining 2024-07-21 00:07:19 +02:00
parent 835faf218d
commit 8349809fec
15 changed files with 256 additions and 41 deletions

21
lib/attrs.nix Normal file
View file

@ -0,0 +1,21 @@
{ lib, ... }:
let
inherit (lib.lists) any count;
inherit (lib.attrsets) filterAttrs listToAttrs mapAttrs' mapAttrsToList;
in rec
{
attrsToList = attrs:
mapAttrsToList (name: value: { inherit name value; }) attrs;
mapFilterAttrs = pred: f: attrs:
filterAttrs pred (mapAttrs' f attrs);
getAttrs' = values: f:
listToAttrs (map f values);
anyAttrs = pred: attrs:
any (attr: pred attr.name attr.value) (attrsToList attrs);
countAttrs = pred: attrs:
count (attr: pred attr.name attr.value) (attrsToList attrs);
}