hasAttr
lib.hasAttr
Primop
Docs pulled from | This Revision | 12 minutes ago
Nix manual
Takes 2 arguments
s, set
hasAttr returns true if set has an attribute named s, and
false otherwise. This is a dynamic version of the ? operator,
since s is an expression rather than an identifier.
Time Complexity
O(log n) where n = 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, const PosIdx pos, Value ** args, Value & v)
{
auto attr = state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.hasAttr");
state.forceAttrs(*args[1], pos, "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