Created
September 16, 2020 22:31
-
-
Save mvnetbiz/1d4143c98ffd7bae357a9eeef4170101 to your computer and use it in GitHub Desktop.
Recurisvely subtract attribute lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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