query
On this page

longestValidPathPrefix

lib.attrsets.longestValidPathPrefix

Docs pulled from | This Revision | about 9 hours ago


Return the longest prefix of an attribute path that refers to an existing attribute in a nesting of attribute sets.

Can be used after mapAttrsRecursiveCond to apply a condition, although this will evaluate the predicate function on sibling attributes as well.

Note that the empty attribute path is valid for all values, so this function only throws an exception if any of its inputs does.

Laws:

  1. attrsets.longestValidPathPrefix [] x == []
    
  2. hasAttrByPath (attrsets.longestValidPathPrefix p x) x == true
    

Inputs

attrPath

A list of strings representing the longest possible path that may be returned.

v

The nested attribute set to check.

Type

attrsets.longestValidPathPrefix :: [String] -> Value -> [String]

Examples

lib.attrsets.longestValidPathPrefix usage example

x = { a = { b = 3; }; }
attrsets.longestValidPathPrefix ["a" "b" "c"] x
=> ["a" "b"]
attrsets.longestValidPathPrefix ["a"] x
=> ["a"]
attrsets.longestValidPathPrefix ["z" "z"] x
=> []
attrsets.longestValidPathPrefix ["z" "z"] (throw "no need")
=> []