diff options
| author | Johannes Kirschbauer <hsjobeki+github@gmail.com> | 2025-11-25 14:15:41 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-25 14:15:41 +0000 |
| commit | 3ae81921625b8a75817421bba2ca2fe49ee5d9cd (patch) | |
| tree | 7c82660e00022890f9344c846f4c8f70ea14f6ed /lib | |
| parent | 364d1f76e07765fabe159d590ed07acb940cbf41 (diff) | |
| parent | 05616bc0f175ccb66346138d20434955c7e97f2e (diff) | |
lib: deprecate fold (#456532)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/lists.nix | 10 | ||||
| -rw-r--r-- | lib/tests/misc.nix | 15 |
2 files changed, 12 insertions, 13 deletions
diff --git a/lib/lists.nix b/lib/lists.nix index a59613f06ef3..fa2a526d1602 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -9,7 +9,6 @@ let min id warn - pipe ; inherit (lib.attrsets) mapAttrs attrNames; inherit (lib) max; @@ -144,10 +143,13 @@ rec { fold' 0; /** - `fold` is an alias of `foldr` for historic reasons + `fold` is an alias of `foldr` for historic reasons. + + ::: {.warning} + This function will be removed in 26.05. + ::: */ - # FIXME(Profpatsch): deprecate? - fold = foldr; + fold = warn "fold has been deprecated, use foldr instead" foldr; /** “left fold”, like `foldr`, but from the left: diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index e4f2222b7685..e24ffa29d4f7 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -1288,25 +1288,23 @@ runTests { expected = [ 15 ]; }; - testFold = + testFoldr = let - f = op: fold: fold op 0 (range 0 100); - # fold with associative operator + f = op: foldr: foldr op 0 (range 0 100); + # foldr with associative operator assoc = f builtins.add; - # fold with non-associative operator + # foldr with non-associative operator nonAssoc = f builtins.sub; in { expr = { assocRight = assoc foldr; - # right fold with assoc operator is same as left fold + # foldr with assoc operator is same as foldl assocRightIsLeft = assoc foldr == assoc foldl; nonAssocRight = nonAssoc foldr; nonAssocLeft = nonAssoc foldl; - # with non-assoc operator the fold results are not the same + # with non-assoc operator the foldr results are not the same nonAssocRightIsNotLeft = nonAssoc foldl != nonAssoc foldr; - # fold is an alias for foldr - foldIsRight = nonAssoc fold == nonAssoc foldr; }; expected = { assocRight = 5050; @@ -1314,7 +1312,6 @@ runTests { nonAssocRight = 50; nonAssocLeft = (-5050); nonAssocRightIsNotLeft = true; - foldIsRight = true; }; }; |
