hasAttr
lib.attrsets.hasAttr
Primop
Docs pulled from | This Revision | 16 minutes ago
Nix manual
Takes 2 arguments
s, set
hasAttr returns true if set has an attribute named s, and false if it does not.
This is a dynamic version of the ? operator, since s is an expression rather than an identifier.
Unlike the ? operator, however, s cannot refer to a nested attribute set.
Also unlike the ? operator, if s is not a string or set is not an attribute set, evaluation is aborted.
Has O(log n) time complexity, where n is number of attributes in the set.
Noogle detected
Detected Type
hasAttr :: String -> AttrSet -> Bool
Implementation
This function is implemented in c++ and is part of the native nix runtime.
static void prim_hasAttr(EvalState & state, CallSite callSite, Value * const * args, Value & v)
{
auto attr =
state.forceStringNoCtx(*args[0], noPos, "while evaluating the first argument passed to builtins.hasAttr");
state.forceAttrs(*args[1], noPos, "while evaluating the second argument passed to builtins.hasAttr");
v.mkBool(args[1]->attrs()->get(state.symbols.create(attr)));
}
Implementation
The following is the current implementation of this function.
hasAttr