elem
lib.lists.elem
Primop
Docs pulled from | This Revision | 18 minutes ago
Nix manual
Takes 2 arguments
x, xs
Return true if a value equal to x occurs in the list xs, and
false otherwise.
Time Complexity
O(n * T) (worst case) where:
n = list length T = time to compare two elements
returns early if the elements is found
Noogle detected
Detected Type
elem :: a -> [b] -> Bool
Implementation
This function is implemented in c++ and is part of the native nix runtime.
static void prim_elem(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
bool res = false;
state.forceList(*args[1], pos, "while evaluating the second argument passed to builtins.elem");
for (auto elem : args[1]->listView())
if (state.eqValues(*args[0], *elem, pos, "while searching for the presence of the given element in the list")) {
res = true;
break;
}
v.mkBool(res);
}