2021-03-10 19:49:12 +01:00
|
|
|
{ lib, ... }:
|
|
|
|
let
|
2021-09-23 21:55:17 +02:00
|
|
|
inherit (lib)
|
|
|
|
filterAttrs
|
|
|
|
foldl
|
|
|
|
listToAttrs
|
|
|
|
mapAttrs'
|
|
|
|
nameValuePair
|
|
|
|
recursiveUpdate
|
|
|
|
;
|
2021-03-10 19:49:12 +01:00
|
|
|
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
|
2021-03-10 19:49:12 +01:00
|
|
|
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);
|
2021-04-03 19:35:14 +02:00
|
|
|
|
2021-09-23 21:55:17 +02:00
|
|
|
# Merge a list of attrs recursively, later values override previous ones.
|
|
|
|
#
|
|
|
|
# recursiveMerge ::
|
|
|
|
# [ attrs ]
|
|
|
|
# attrs
|
|
|
|
recursiveMerge = foldl recursiveUpdate { };
|
|
|
|
|
2021-04-03 19:35:14 +02:00
|
|
|
# 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);
|
2021-03-10 19:49:12 +01:00
|
|
|
}
|