From 2c55c4aae4a67af469db9bf0328666e975d6b23d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 30 Dec 2025 19:09:59 +0100 Subject: [PATCH] Revert "Add `builtins.imap` function" This reverts commit 4db99ea955d6391ec94c9703d4f74b3c1ba1d73d. --- src/libexpr/primops/imap.cc | 46 ------------------------ src/libexpr/primops/meson.build | 1 - tests/functional/lang/eval-okay-imap.exp | 1 - tests/functional/lang/eval-okay-imap.nix | 8 ----- 4 files changed, 56 deletions(-) delete mode 100644 src/libexpr/primops/imap.cc delete mode 100644 tests/functional/lang/eval-okay-imap.exp delete mode 100644 tests/functional/lang/eval-okay-imap.nix diff --git a/src/libexpr/primops/imap.cc b/src/libexpr/primops/imap.cc deleted file mode 100644 index a7c412dd1..000000000 --- a/src/libexpr/primops/imap.cc +++ /dev/null @@ -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 diff --git a/src/libexpr/primops/meson.build b/src/libexpr/primops/meson.build index 73fa3911d..b8abc6409 100644 --- a/src/libexpr/primops/meson.build +++ b/src/libexpr/primops/meson.build @@ -9,5 +9,4 @@ sources += files( 'fetchMercurial.cc', 'fetchTree.cc', 'fromTOML.cc', - 'imap.cc', ) diff --git a/tests/functional/lang/eval-okay-imap.exp b/tests/functional/lang/eval-okay-imap.exp deleted file mode 100644 index 5ede7fa19..000000000 --- a/tests/functional/lang/eval-okay-imap.exp +++ /dev/null @@ -1 +0,0 @@ -[ "a-0" "b-1" "a-1" "b-2" ] diff --git a/tests/functional/lang/eval-okay-imap.nix b/tests/functional/lang/eval-okay-imap.nix deleted file mode 100644 index 63a9ffb26..000000000 --- a/tests/functional/lang/eval-okay-imap.nix +++ /dev/null @@ -1,8 +0,0 @@ -(builtins.imap 0 (i: v: "${v}-${toString i}") [ - "a" - "b" -]) -++ (builtins.imap 1 (i: v: "${v}-${toString i}") [ - "a" - "b" -])