diff options
author | Christian Zagrodnick <cz@flyingcircus.io> | 2015-12-04 16:17:45 +0100 |
---|---|---|
committer | Christian Zagrodnick <cz@flyingcircus.io> | 2015-12-07 11:04:14 +0100 |
commit | ce96057588821156d08b48cf8647b6cb8730e63c (patch) | |
tree | 5dafb789ce93fb3e05fcf41ed168182a14eca41b /lib/attrsets.nix | |
parent | ff66ac9dd089778154a8197c84a87fcd302d66fa (diff) |
add helper to lib/attrsets: hasAttrByPath
Diffstat (limited to 'lib/attrsets.nix')
-rw-r--r-- | lib/attrsets.nix | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 22ecc808679d0..84f6cb3658b90 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -23,6 +23,17 @@ rec { then attrByPath (tail attrPath) default e.${attr} else default; + /* Return if an attribute from nested attribute set exists. + For instance ["x" "y"] applied to some set e returns true, if e.x.y exists. False + is returned otherwise. */ + hasAttrByPath = attrPath: e: + let attr = head attrPath; + in + if attrPath == [] then true + else if e ? ${attr} + then hasAttrByPath (tail attrPath) e.${attr} + else false; + /* Return nested attribute set in which an attribute is set. For instance ["x" "y"] applied with some value v returns `x.y = v;' */ |