Skip to content

Instantly share code, notes, and snippets.

@mvnetbiz
Created September 16, 2020 22:31
Show Gist options
  • Select an option

  • Save mvnetbiz/1d4143c98ffd7bae357a9eeef4170101 to your computer and use it in GitHub Desktop.

Select an option

Save mvnetbiz/1d4143c98ffd7bae357a9eeef4170101 to your computer and use it in GitHub Desktop.
Recurisvely subtract attribute lists
a1: a2:
let
lib = (import <nixpkgs> {}).lib;
xor = a: b: (a && !b) || (!a && b);
subtractAttrs = a: b: with lib;
let
attrsAttrsNames = x: filter (e: (isAttrs x.${e})) (attrNames x);
bothAttrs = intersectLists (attrsAttrsNames a) (attrsAttrsNames b);
in
(filterAttrs (name: value:
(!(hasAttr name b))
|| (xor (isAttrs value) (isAttrs b.${name}))
|| (value != b.${name})
) a)
// (genAttrs bothAttrs (name: subtractAttrs a.${name} b.${name}));
in
subtractAttrs a1 a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment