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:
parent
31d23ba418
commit
46fd25dda9
1 changed files with 5 additions and 26 deletions
|
@ -4,7 +4,6 @@ let
|
|||
inherit (lib.strings) toInt;
|
||||
inherit (lib.trivial) compare min id warn;
|
||||
inherit (lib.attrsets) mapAttrs;
|
||||
inherit (lib.lists) sort;
|
||||
in
|
||||
rec {
|
||||
|
||||
|
@ -172,7 +171,7 @@ rec {
|
|||
concatMap (x: [x] ++ ["z"]) ["a" "b"]
|
||||
=> [ "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
|
||||
spliced into the top-level lists.
|
||||
|
@ -316,7 +315,7 @@ rec {
|
|||
any isString [ 1 { } ]
|
||||
=> 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
|
||||
`list`.
|
||||
|
@ -329,7 +328,7 @@ rec {
|
|||
all (x: x < 3) [ 1 2 3 ]
|
||||
=> 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
|
||||
function.
|
||||
|
@ -428,12 +427,7 @@ rec {
|
|||
partition (x: x > 2) [ 5 1 2 3 4 ]
|
||||
=> { right = [ 5 3 4 ]; wrong = [ 1 2 ]; }
|
||||
*/
|
||||
partition = builtins.partition or (pred:
|
||||
foldr (h: t:
|
||||
if pred h
|
||||
then { right = [h] ++ t.right; wrong = t.wrong; }
|
||||
else { right = t.right; wrong = [h] ++ t.wrong; }
|
||||
) { right = []; wrong = []; });
|
||||
partition = builtins.partition;
|
||||
|
||||
/* 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.
|
||||
|
@ -602,22 +596,7 @@ rec {
|
|||
Type:
|
||||
sort :: (a -> a -> Bool) -> [a] -> [a]
|
||||
*/
|
||||
sort = builtins.sort or (
|
||||
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 = builtins.sort;
|
||||
|
||||
/*
|
||||
Sort a list based on the default comparison of a derived property `b`.
|
||||
|
|
Loading…
Reference in a new issue