Remove unecessary branching on old nix versions
All these builtins are available since 1.10 or earlier (1.10 being the lib/minver.nix)
This commit is contained in:
parent
9bbac1f4ea
commit
bec28d748c
|
@ -68,18 +68,7 @@ rec {
|
||||||
imap (i: v: "${v}-${toString i}") ["a" "b"]
|
imap (i: v: "${v}-${toString i}") ["a" "b"]
|
||||||
=> [ "a-1" "b-2" ]
|
=> [ "a-1" "b-2" ]
|
||||||
*/
|
*/
|
||||||
imap =
|
imap = f: list: genList (n: f (n + 1) (elemAt list n)) (length list);
|
||||||
if builtins ? genList then
|
|
||||||
f: list: genList (n: f (n + 1) (elemAt list n)) (length list)
|
|
||||||
else
|
|
||||||
f: list:
|
|
||||||
let
|
|
||||||
len = length list;
|
|
||||||
imap' = n:
|
|
||||||
if n == len
|
|
||||||
then []
|
|
||||||
else [ (f (n + 1) (elemAt list n)) ] ++ imap' (n + 1);
|
|
||||||
in imap' 0;
|
|
||||||
|
|
||||||
/* Map and concatenate the result.
|
/* Map and concatenate the result.
|
||||||
|
|
||||||
|
@ -216,17 +205,11 @@ rec {
|
||||||
range 3 2
|
range 3 2
|
||||||
=> [ ]
|
=> [ ]
|
||||||
*/
|
*/
|
||||||
range =
|
range = first: last:
|
||||||
if builtins ? genList then
|
if first > last then
|
||||||
first: last:
|
[]
|
||||||
if first > last
|
|
||||||
then []
|
|
||||||
else genList (n: first + n) (last - first + 1)
|
|
||||||
else
|
else
|
||||||
first: last:
|
genList (n: first + n) (last - first + 1);
|
||||||
if last < first
|
|
||||||
then []
|
|
||||||
else [first] ++ range (first + 1) last;
|
|
||||||
|
|
||||||
/* Splits the elements of a list in two lists, `right' and
|
/* Splits the elements of a list in two lists, `right' and
|
||||||
`wrong', depending on the evaluation of a predicate.
|
`wrong', depending on the evaluation of a predicate.
|
||||||
|
@ -250,19 +233,9 @@ rec {
|
||||||
zipListsWith (a: b: a + b) ["h" "l"] ["e" "o"]
|
zipListsWith (a: b: a + b) ["h" "l"] ["e" "o"]
|
||||||
=> ["he" "lo"]
|
=> ["he" "lo"]
|
||||||
*/
|
*/
|
||||||
zipListsWith =
|
zipListsWith = f: fst: snd:
|
||||||
if builtins ? genList then
|
genList
|
||||||
f: fst: snd: genList (n: f (elemAt fst n) (elemAt snd n)) (min (length fst) (length snd))
|
(n: f (elemAt fst n) (elemAt snd n)) (min (length fst) (length snd));
|
||||||
else
|
|
||||||
f: fst: snd:
|
|
||||||
let
|
|
||||||
len = min (length fst) (length snd);
|
|
||||||
zipListsWith' = n:
|
|
||||||
if n != len then
|
|
||||||
[ (f (elemAt fst n) (elemAt snd n)) ]
|
|
||||||
++ zipListsWith' (n + 1)
|
|
||||||
else [];
|
|
||||||
in zipListsWith' 0;
|
|
||||||
|
|
||||||
/* Merges two lists of the same size together. If the sizes aren't the same
|
/* Merges two lists of the same size together. If the sizes aren't the same
|
||||||
the merging stops at the shortest.
|
the merging stops at the shortest.
|
||||||
|
@ -280,11 +253,8 @@ rec {
|
||||||
reverseList [ "b" "o" "j" ]
|
reverseList [ "b" "o" "j" ]
|
||||||
=> [ "j" "o" "b" ]
|
=> [ "j" "o" "b" ]
|
||||||
*/
|
*/
|
||||||
reverseList =
|
reverseList = xs:
|
||||||
if builtins ? genList then
|
let l = length xs; in genList (n: elemAt xs (l - n - 1)) l;
|
||||||
xs: let l = length xs; in genList (n: elemAt xs (l - n - 1)) l
|
|
||||||
else
|
|
||||||
fold (e: acc: acc ++ [ e ]) [];
|
|
||||||
|
|
||||||
/* Sort a list based on a comparator function which compares two
|
/* Sort a list based on a comparator function which compares two
|
||||||
elements and returns true if the first argument is strictly below
|
elements and returns true if the first argument is strictly below
|
||||||
|
@ -320,19 +290,7 @@ rec {
|
||||||
take 2 [ ]
|
take 2 [ ]
|
||||||
=> [ ]
|
=> [ ]
|
||||||
*/
|
*/
|
||||||
take =
|
take = count: sublist 0 count;
|
||||||
if builtins ? genList then
|
|
||||||
count: sublist 0 count
|
|
||||||
else
|
|
||||||
count: list:
|
|
||||||
let
|
|
||||||
len = length list;
|
|
||||||
take' = n:
|
|
||||||
if n == len || n == count
|
|
||||||
then []
|
|
||||||
else
|
|
||||||
[ (elemAt list n) ] ++ take' (n + 1);
|
|
||||||
in take' 0;
|
|
||||||
|
|
||||||
/* Remove the first (at most) N elements of a list.
|
/* Remove the first (at most) N elements of a list.
|
||||||
|
|
||||||
|
@ -342,19 +300,7 @@ rec {
|
||||||
drop 2 [ ]
|
drop 2 [ ]
|
||||||
=> [ ]
|
=> [ ]
|
||||||
*/
|
*/
|
||||||
drop =
|
drop = count: list: sublist count (length list) list;
|
||||||
if builtins ? genList then
|
|
||||||
count: list: sublist count (length list) list
|
|
||||||
else
|
|
||||||
count: list:
|
|
||||||
let
|
|
||||||
len = length list;
|
|
||||||
drop' = n:
|
|
||||||
if n == -1 || n < count
|
|
||||||
then []
|
|
||||||
else
|
|
||||||
drop' (n - 1) ++ [ (elemAt list n) ];
|
|
||||||
in drop' (len - 1);
|
|
||||||
|
|
||||||
/* Return a list consisting of at most ‘count’ elements of ‘list’,
|
/* Return a list consisting of at most ‘count’ elements of ‘list’,
|
||||||
starting at index ‘start’.
|
starting at index ‘start’.
|
||||||
|
|
|
@ -16,11 +16,7 @@ rec {
|
||||||
concatStrings ["foo" "bar"]
|
concatStrings ["foo" "bar"]
|
||||||
=> "foobar"
|
=> "foobar"
|
||||||
*/
|
*/
|
||||||
concatStrings =
|
concatStrings = builtins.concatStringsSep "";
|
||||||
if builtins ? concatStringsSep then
|
|
||||||
builtins.concatStringsSep ""
|
|
||||||
else
|
|
||||||
lib.foldl' (x: y: x + y) "";
|
|
||||||
|
|
||||||
/* Map a function over a list and concatenate the resulting strings.
|
/* Map a function over a list and concatenate the resulting strings.
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,9 @@ let
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
toPath = builtins.toPath;
|
toPath = builtins.toPath;
|
||||||
getEnv = x: if builtins ? getEnv then builtins.getEnv x else "";
|
getEnv = builtins.getEnv;
|
||||||
pathExists = name:
|
pathExists = name:
|
||||||
builtins ? pathExists && builtins.pathExists (toPath name);
|
builtins.pathExists (toPath name);
|
||||||
|
|
||||||
configFile = getEnv "NIXPKGS_CONFIG";
|
configFile = getEnv "NIXPKGS_CONFIG";
|
||||||
homeDir = getEnv "HOME";
|
homeDir = getEnv "HOME";
|
||||||
|
|
Loading…
Reference in New Issue