attrNames
lib.attrNames
Primop
Docs pulled from | This Revision | 29 minutes ago
Nix manual
Takes 1 arguments
set
Return the names of the attributes in the set set in an
alphabetically sorted list. For instance, builtins.attrNames { y = 1; x = "foo"; } evaluates to [ "x" "y" ].
Time Complexity
- O(n log n), where:
n = number of attributes in the set
Noogle detected
Detected Type
attrNames :: AttrSet -> [String]
Implementation
This function is implemented in c++ and is part of the native nix runtime.
static void prim_attrNames(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
state.forceAttrs(*args[0], pos, "while evaluating the argument passed to builtins.attrNames");
auto list = state.buildList(args[0]->attrs()->size());
for (const auto & [n, i] : enumerate(*args[0]->attrs()))
list[n] = Value::toPtr(state.symbols[i.name]);
std::sort(list.begin(), list.end(), [](Value * v1, Value * v2) { return v1->string_view() < v2->string_view(); });
v.mkList(list);
}
Implementation
The following is the current implementation of this function.
attrNames