Created
April 4, 2023 15:39
-
-
Save maxsei/57ee470aef0b9cc8a81e008e85e69d3c to your computer and use it in GitHub Desktop.
Get the keys of a nested object in a flat data structure in nix
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
| let | |
| flatkeys = cur: | |
| if builtins.isAttrs cur then | |
| (builtins.concatMap | |
| (k: builtins.map (x: [ k ] ++ x) (flatkeys cur."${k}")) | |
| (builtins.attrNames cur)) | |
| else if builtins.isList cur then | |
| builtins.concatLists (builtins.genList | |
| (i: builtins.map (x: [ i ] ++ x) (flatkeys (builtins.elemAt cur i))) | |
| (builtins.length cur)) | |
| else | |
| [ [ ] ]; | |
| in | |
| flatkeys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment