mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-10-30 06:01:19 +00:00
Merge pull request #287369 from tweag/lib-remove-polyfills
`lib`: Remove unneeded polyfills
This commit is contained in:
commit
d0f7816d14
@ -2,10 +2,10 @@
|
||||
{ lib }:
|
||||
|
||||
let
|
||||
inherit (builtins) head tail length;
|
||||
inherit (lib.trivial) id mergeAttrs warn;
|
||||
inherit (builtins) head length;
|
||||
inherit (lib.trivial) mergeAttrs warn;
|
||||
inherit (lib.strings) concatStringsSep concatMapStringsSep escapeNixIdentifier sanitizeDerivationName;
|
||||
inherit (lib.lists) foldr foldl' concatMap concatLists elemAt all partition groupBy take foldl;
|
||||
inherit (lib.lists) foldr foldl' concatMap elemAt all partition groupBy take foldl;
|
||||
in
|
||||
|
||||
rec {
|
||||
@ -369,7 +369,7 @@ rec {
|
||||
Type:
|
||||
attrValues :: AttrSet -> [Any]
|
||||
*/
|
||||
attrValues = builtins.attrValues or (attrs: attrVals (attrNames attrs) attrs);
|
||||
attrValues = builtins.attrValues;
|
||||
|
||||
|
||||
/* Given a set of attribute names, return the set of the corresponding
|
||||
@ -398,8 +398,7 @@ rec {
|
||||
Type:
|
||||
catAttrs :: String -> [AttrSet] -> [Any]
|
||||
*/
|
||||
catAttrs = builtins.catAttrs or
|
||||
(attr: l: concatLists (map (s: if s ? ${attr} then [s.${attr}] else []) l));
|
||||
catAttrs = builtins.catAttrs;
|
||||
|
||||
|
||||
/* Filter an attribute set by removing all attributes for which the
|
||||
@ -608,9 +607,7 @@ rec {
|
||||
Type:
|
||||
mapAttrs :: (String -> Any -> Any) -> AttrSet -> AttrSet
|
||||
*/
|
||||
mapAttrs = builtins.mapAttrs or
|
||||
(f: set:
|
||||
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
|
||||
mapAttrs = builtins.mapAttrs;
|
||||
|
||||
|
||||
/* Like `mapAttrs`, but allows the name of each attribute to be
|
||||
|
@ -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`.
|
||||
|
@ -95,8 +95,7 @@ rec {
|
||||
concatStringsSep "/" ["usr" "local" "bin"]
|
||||
=> "usr/local/bin"
|
||||
*/
|
||||
concatStringsSep = builtins.concatStringsSep or (separator: list:
|
||||
lib.foldl' (x: y: x + y) "" (intersperse separator list));
|
||||
concatStringsSep = builtins.concatStringsSep;
|
||||
|
||||
/* Maps a function over a list of strings and then concatenates the
|
||||
result with the specified separator interspersed between
|
||||
|
@ -95,21 +95,6 @@ in {
|
||||
/* boolean “and” */
|
||||
and = x: y: x && y;
|
||||
|
||||
/* bitwise “and” */
|
||||
bitAnd = builtins.bitAnd
|
||||
or (import ./zip-int-bits.nix
|
||||
(a: b: if a==1 && b==1 then 1 else 0));
|
||||
|
||||
/* bitwise “or” */
|
||||
bitOr = builtins.bitOr
|
||||
or (import ./zip-int-bits.nix
|
||||
(a: b: if a==1 || b==1 then 1 else 0));
|
||||
|
||||
/* bitwise “xor” */
|
||||
bitXor = builtins.bitXor
|
||||
or (import ./zip-int-bits.nix
|
||||
(a: b: if a!=b then 1 else 0));
|
||||
|
||||
/* bitwise “not” */
|
||||
bitNot = builtins.sub (-1);
|
||||
|
||||
@ -165,8 +150,8 @@ in {
|
||||
inherit (builtins)
|
||||
pathExists readFile isBool
|
||||
isInt isFloat add sub lessThan
|
||||
seq deepSeq genericClosure;
|
||||
|
||||
seq deepSeq genericClosure
|
||||
bitAnd bitOr bitXor;
|
||||
|
||||
## nixpkgs version strings
|
||||
|
||||
|
@ -9,7 +9,7 @@ rec {
|
||||
splitVersion "1.2.3"
|
||||
=> ["1" "2" "3"]
|
||||
*/
|
||||
splitVersion = builtins.splitVersion or (lib.splitString ".");
|
||||
splitVersion = builtins.splitVersion;
|
||||
|
||||
/* Get the major version string from a string.
|
||||
|
||||
|
@ -1,39 +0,0 @@
|
||||
/* Helper function to implement a fallback for the bit operators
|
||||
`bitAnd`, `bitOr` and `bitXor` on older nix version.
|
||||
See ./trivial.nix
|
||||
*/
|
||||
f: x: y:
|
||||
let
|
||||
# (intToBits 6) -> [ 0 1 1 ]
|
||||
intToBits = x:
|
||||
if x == 0 || x == -1 then
|
||||
[]
|
||||
else
|
||||
let
|
||||
headbit = if (x / 2) * 2 != x then 1 else 0; # x & 1
|
||||
tailbits = if x < 0 then ((x + 1) / 2) - 1 else x / 2; # x >> 1
|
||||
in
|
||||
[headbit] ++ (intToBits tailbits);
|
||||
|
||||
# (bitsToInt [ 0 1 1 ] 0) -> 6
|
||||
# (bitsToInt [ 0 1 0 ] 1) -> -6
|
||||
bitsToInt = l: signum:
|
||||
if l == [] then
|
||||
(if signum == 0 then 0 else -1)
|
||||
else
|
||||
(builtins.head l) + (2 * (bitsToInt (builtins.tail l) signum));
|
||||
|
||||
xsignum = if x < 0 then 1 else 0;
|
||||
ysignum = if y < 0 then 1 else 0;
|
||||
zipListsWith' = fst: snd:
|
||||
if fst==[] && snd==[] then
|
||||
[]
|
||||
else if fst==[] then
|
||||
[(f xsignum (builtins.head snd))] ++ (zipListsWith' [] (builtins.tail snd))
|
||||
else if snd==[] then
|
||||
[(f (builtins.head fst) ysignum )] ++ (zipListsWith' (builtins.tail fst) [] )
|
||||
else
|
||||
[(f (builtins.head fst) (builtins.head snd))] ++ (zipListsWith' (builtins.tail fst) (builtins.tail snd));
|
||||
in
|
||||
assert (builtins.isInt x) && (builtins.isInt y);
|
||||
bitsToInt (zipListsWith' (intToBits x) (intToBits y)) (f xsignum ysignum)
|
Loading…
Reference in New Issue
Block a user