Revert "Add builtins.imap function"

This reverts commit 4db99ea955.
This commit is contained in:
Eelco Dolstra
2025-12-30 19:09:59 +01:00
parent 80c9ad7de4
commit 2c55c4aae4
4 changed files with 0 additions and 56 deletions

View File

@@ -1,46 +0,0 @@
#include "nix/expr/primops.hh"
namespace nix {
static void prim_imap(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
auto shift = state.forceInt(*args[0], pos, "while evaluating the first argument passed to 'builtins.imap'").value;
Value & f = *args[1];
Value & list = *args[2];
state.forceList(list, pos, "while evaluating the third argument passed to 'builtins.imap'");
if (list.listSize() == 0) {
v = list;
return;
}
auto outList = state.buildList(list.listSize());
for (const auto & [n, v] : enumerate(outList)) {
v = state.allocValue();
auto vIdx = state.allocValue();
vIdx->mkInt(n + shift);
Value * args[] = {vIdx, list.listView()[n]};
state.callFunction(f, args, *v, pos);
}
v.mkList(outList);
}
static RegisterPrimOp primop_imap(
{.name = "__imap",
.args = {"shift", "f", "list"},
.doc = R"(
Apply the function *f* to each element in the list *list*. The function *f* is called with two arguments: the index of the element (plus *shift*) and the element itself.
For example,
```nix
builtins.imap 1 (i: v: "${v}-${toString i}") ["a" "b"]
```
evaluates to `[ "a-1" "b-2" ]`.
)",
.fun = prim_imap});
} // namespace nix

View File

@@ -9,5 +9,4 @@ sources += files(
'fetchMercurial.cc',
'fetchTree.cc',
'fromTOML.cc',
'imap.cc',
)

View File

@@ -1 +0,0 @@
[ "a-0" "b-1" "a-1" "b-2" ]

View File

@@ -1,8 +0,0 @@
(builtins.imap 0 (i: v: "${v}-${toString i}") [
"a"
"b"
])
++ (builtins.imap 1 (i: v: "${v}-${toString i}") [
"a"
"b"
])