lib.attrsets.hasAttrByPath: Document law and laziness, and test it
This commit is contained in:
parent
72bd4bbb58
commit
7d993b9521
@ -51,12 +51,19 @@ rec {
|
||||
|
||||
/* Return if an attribute from nested attribute set exists.
|
||||
|
||||
**Laws**:
|
||||
1. ```nix
|
||||
hasAttrByPath [] x == true
|
||||
```
|
||||
|
||||
Example:
|
||||
x = { a = { b = 3; }; }
|
||||
hasAttrByPath ["a" "b"] x
|
||||
=> true
|
||||
hasAttrByPath ["z" "z"] x
|
||||
=> false
|
||||
hasAttrByPath [] (throw "no need")
|
||||
=> true
|
||||
|
||||
Type:
|
||||
hasAttrByPath :: [String] -> AttrSet -> Bool
|
||||
|
@ -697,6 +697,11 @@ runTests {
|
||||
expected = false;
|
||||
};
|
||||
|
||||
testHasAttrByPathNonStrict = {
|
||||
expr = hasAttrByPath [] (throw "do not use");
|
||||
expected = true;
|
||||
};
|
||||
|
||||
testLongestValidPathPrefix_empty_empty = {
|
||||
expr = attrsets.longestValidPathPrefix [ ] { };
|
||||
expected = [ ];
|
||||
|
Loading…
Reference in New Issue
Block a user