rework lib and some general changes
This commit is contained in:
parent
48b7ab9fab
commit
af804c63f8
11 changed files with 152 additions and 121 deletions
25
lib/attrs.nix
Normal file
25
lib/attrs.nix
Normal file
|
@ -0,0 +1,25 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib.lists) any count;
|
||||
inherit (lib.attrsets) filterAttrs listToAttrs mapAttrs' mapAttrsToList;
|
||||
in rec {
|
||||
# attrsToList
|
||||
attrsToList = attrs:
|
||||
mapAttrsToList (name: value: {inherit name value;}) attrs;
|
||||
|
||||
# mapFilterAttrs ::
|
||||
# (name -> value -> bool)
|
||||
# (name -> value -> { name = any; value = any; })
|
||||
# attrs
|
||||
mapFilterAttrs = pred: f: attrs: filterAttrs pred (mapAttrs' f attrs);
|
||||
|
||||
# Generate an attribute set by mapping a function over a list of values.
|
||||
genAttrs' = values: f: listToAttrs (map f values);
|
||||
|
||||
# anyAttrs :: (name -> value -> bool) attrs
|
||||
anyAttrs = pred: attrs:
|
||||
any (attr: pred attr.name attr.value) (attrsToList attrs);
|
||||
|
||||
# countAttrs :: (name -> value -> bool) attrs
|
||||
countAttrs = pred: attrs:
|
||||
count (attr: pred attr.name attr.value) (attrsToList attrs);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue