diff options
author | Alyssa Ross <hi@alyssa.is> | 2024-03-01 11:40:12 +0100 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2024-03-01 11:40:12 +0100 |
commit | bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86 (patch) | |
tree | 8eb035cbab19794f6415cc460fac7226f7a58afc /nixpkgs/lib/lists.nix | |
parent | 66f707d69f1e423db5a35c2fe43b32781125a9af (diff) | |
parent | 09c1497ce5d4ed4a0edfdd44450d3048074cb300 (diff) | |
download | nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.gz nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.bz2 nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.lz nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.xz nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.zst nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.zip |
Merge branch 'nixos-unstable-small' of https://github.com/NixOS/nixpkgs
Diffstat (limited to 'nixpkgs/lib/lists.nix')
-rw-r--r-- | nixpkgs/lib/lists.nix | 31 |
1 files changed, 5 insertions, 26 deletions
diff --git a/nixpkgs/lib/lists.nix b/nixpkgs/lib/lists.nix index b612bc16697e..05216c1a66eb 100644 --- a/nixpkgs/lib/lists.nix +++ b/nixpkgs/lib/lists.nix @@ -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`. |