query
On this page

elem

lib.elem

Primop
Docs pulled from | This Revision | 18 days ago


Nix manual

Takes 2 arguments

x, xs

Return true if a value equal to x occurs in the list xs, and false otherwise. Short-circuits and does not evaluate elements that occur in the list after the first match.

Noogle detected

Aliases

Detected Type
elem :: a -> [b] -> Bool

Implementation

This function is implemented in c++ and is part of the native nix runtime.

src/libexpr/primops.cc:3938

static void prim_elem(EvalState & state, CallSite callSite, Value * const * args, Value & v)
{
    bool res = false;
    state.forceList(*args[1], noPos, "while evaluating the second argument passed to builtins.elem");
    for (auto elem : args[1]->listView())
        if (state.eqValues(
                *args[0], *elem, noPos, "while searching for the presence of the given element in the list")) {
            res = true;
            break;
        }
    v.mkBool(res);
}

Implementation

The following is the current implementation of this function.

elem