lib.lists: Remove unneeded polyfills

Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
This commit is contained in:
Silvan Mosberger 2024-02-09 05:35:39 +01:00
parent 31d23ba418
commit 46fd25dda9

View file

@ -4,7 +4,6 @@ let
inherit (lib.strings) toInt; inherit (lib.strings) toInt;
inherit (lib.trivial) compare min id warn; inherit (lib.trivial) compare min id warn;
inherit (lib.attrsets) mapAttrs; inherit (lib.attrsets) mapAttrs;
inherit (lib.lists) sort;
in in
rec { rec {
@ -172,7 +171,7 @@ rec {
concatMap (x: [x] ++ ["z"]) ["a" "b"] concatMap (x: [x] ++ ["z"]) ["a" "b"]
=> [ "a" "z" "b" "z" ] => [ "a" "z" "b" "z" ]
*/ */
concatMap = builtins.concatMap or (f: list: concatLists (map f list)); concatMap = builtins.concatMap;
/* Flatten the argument into a single list; that is, nested lists are /* Flatten the argument into a single list; that is, nested lists are
spliced into the top-level lists. spliced into the top-level lists.
@ -316,7 +315,7 @@ rec {
any isString [ 1 { } ] any isString [ 1 { } ]
=> false => false
*/ */
any = builtins.any or (pred: foldr (x: y: if pred x then true else y) false); any = builtins.any;
/* Return true if function `pred` returns true for all elements of /* Return true if function `pred` returns true for all elements of
`list`. `list`.
@ -329,7 +328,7 @@ rec {
all (x: x < 3) [ 1 2 3 ] all (x: x < 3) [ 1 2 3 ]
=> false => false
*/ */
all = builtins.all or (pred: foldr (x: y: if pred x then y else false) true); all = builtins.all;
/* Count how many elements of `list` match the supplied predicate /* Count how many elements of `list` match the supplied predicate
function. function.
@ -428,12 +427,7 @@ rec {
partition (x: x > 2) [ 5 1 2 3 4 ] partition (x: x > 2) [ 5 1 2 3 4 ]
=> { right = [ 5 3 4 ]; wrong = [ 1 2 ]; } => { right = [ 5 3 4 ]; wrong = [ 1 2 ]; }
*/ */
partition = builtins.partition or (pred: partition = builtins.partition;
foldr (h: t:
if pred h
then { right = [h] ++ t.right; wrong = t.wrong; }
else { right = t.right; wrong = [h] ++ t.wrong; }
) { right = []; wrong = []; });
/* Splits the elements of a list into many lists, using the return value of a predicate. /* Splits the elements of a list into many lists, using the return value of a predicate.
Predicate should return a string which becomes keys of attrset `groupBy` returns. Predicate should return a string which becomes keys of attrset `groupBy` returns.
@ -602,22 +596,7 @@ rec {
Type: Type:
sort :: (a -> a -> Bool) -> [a] -> [a] sort :: (a -> a -> Bool) -> [a] -> [a]
*/ */
sort = builtins.sort or ( sort = builtins.sort;
strictLess: list:
let
len = length list;
first = head list;
pivot' = n: acc@{ left, right }: let el = elemAt list n; next = pivot' (n + 1); in
if n == len
then acc
else if strictLess first el
then next { inherit left; right = [ el ] ++ right; }
else
next { left = [ el ] ++ left; inherit right; };
pivot = pivot' 1 { left = []; right = []; };
in
if len < 2 then list
else (sort strictLess pivot.left) ++ [ first ] ++ (sort strictLess pivot.right));
/* /*
Sort a list based on the default comparison of a derived property `b`. Sort a list based on the default comparison of a derived property `b`.