head
lib.strings.head
Primop
Docs pulled from | This Revision | about 1 hour ago
Nix manual
Takes 1 arguments
list
Return the first element of a list; abort evaluation if the argument
isn’t a list or is an empty list. You can test whether a list is
empty by comparing it with [].
Time Complexity
O(1)
Noogle detected
Detected Type
head :: [a] -> a
Implementation
This function is implemented in c++ and is part of the native nix runtime.
static void prim_head(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
state.forceList(*args[0], pos, "while evaluating the first argument passed to 'builtins.head'");
if (args[0]->listSize() == 0)
state.error<EvalError>("'builtins.head' called on an empty list").atPos(pos).debugThrow();
state.forceValue(*args[0]->listView()[0], pos);
v = *args[0]->listView()[0];
}