From cd7c8e2172943f00331d44d4b49d7f8c201e42d7 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 3 Apr 2021 17:35:14 +0000 Subject: [PATCH] lib: attrs: add renaming functions --- lib/attrs.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/attrs.nix b/lib/attrs.nix index 7b86aaa..84b63c7 100644 --- a/lib/attrs.nix +++ b/lib/attrs.nix @@ -1,6 +1,6 @@ { lib, ... }: let - inherit (lib) filterAttrs listToAttrs mapAttrs'; + inherit (lib) filterAttrs listToAttrs mapAttrs' nameValuePair; in { # Filter a generated set of attrs using a predicate function. @@ -18,4 +18,19 @@ in # (value -> { name = any; value = any; }) # attrs 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); }