lib: attrs: add renaming functions
This commit is contained in:
parent
e0b0f44a9a
commit
cd7c8e2172
|
@ -1,6 +1,6 @@
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) filterAttrs listToAttrs mapAttrs';
|
inherit (lib) filterAttrs listToAttrs mapAttrs' nameValuePair;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Filter a generated set of attrs using a predicate function.
|
# Filter a generated set of attrs using a predicate function.
|
||||||
|
@ -18,4 +18,19 @@ in
|
||||||
# (value -> { name = any; value = any; })
|
# (value -> { name = any; value = any; })
|
||||||
# attrs
|
# attrs
|
||||||
genAttrs' = values: f: listToAttrs (map f values);
|
genAttrs' = values: f: listToAttrs (map f values);
|
||||||
|
|
||||||
|
# Rename each of the attributes in an attribute set using the mapping function
|
||||||
|
#
|
||||||
|
# renameAttrs ::
|
||||||
|
# (name -> new name)
|
||||||
|
# attrs
|
||||||
|
renameAttrs = f: mapAttrs' (name: value: nameValuePair (f name) value);
|
||||||
|
|
||||||
|
# Rename each of the attributes in an attribute set using a function which
|
||||||
|
# takes the attribute's name and value as inputs.
|
||||||
|
#
|
||||||
|
# renameAttrs' ::
|
||||||
|
# (name -> value -> new name)
|
||||||
|
# attrs
|
||||||
|
renameAttrs' = f: mapAttrs' (name: value: nameValuePair (f name value) value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue