Remove need to specify lib
This commit is contained in:
parent
0ca34d3bdc
commit
01b972fe3d
25
util.nix
25
util.nix
@ -1,30 +1,29 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
lib = import <nixpkgs/lib>;
|
lib = import <nixpkgs/lib>;
|
||||||
utils = rec {
|
utils = with lib; rec {
|
||||||
inherit lib;
|
|
||||||
# Passthrough trace for debugging
|
# Passthrough trace for debugging
|
||||||
pTrace = v: lib.traceSeq v v;
|
pTrace = v: traceSeq v v;
|
||||||
# find the total sum of a int list
|
# find the total sum of a int list
|
||||||
sum = lib.foldr (x: y: x + y) 0;
|
sum = foldr (x: y: x + y) 0;
|
||||||
# splits a list of length two into two params then they're passed to a func
|
# splits a list of length two into two params then they're passed to a func
|
||||||
split = pair: f: f (lib.head pair) (lib.last pair);
|
split = pair: f: f (head pair) (last pair);
|
||||||
# Finds the max value in a list
|
# Finds the max value in a list
|
||||||
maxList = lib.foldr lib.max 0;
|
maxList = foldr max 0;
|
||||||
# Sorts a int list. Greatest value first
|
# Sorts a int list. Greatest value first
|
||||||
sortList = lib.sort (x: y: x > y);
|
sortList = sort (x: y: x > y);
|
||||||
# Cuts a list in half and returns the two parts in a list
|
# Cuts a list in half and returns the two parts in a list
|
||||||
cutInHalf = l: [(lib.take (lib.length l / 2) l) (lib.drop (lib.length l / 2) l)];
|
cutInHalf = l: [(take (length l / 2) l) (drop (length l / 2) l)];
|
||||||
# Splits a list into a list of lists with length cnt
|
# Splits a list into a list of lists with length cnt
|
||||||
chunksOf = cnt: l:
|
chunksOf = cnt: l:
|
||||||
if lib.length l >= cnt then
|
if length l >= cnt then
|
||||||
[(lib.take cnt l)] ++ chunksOf cnt (lib.drop cnt l)
|
[(take cnt l)] ++ chunksOf cnt (drop cnt l)
|
||||||
else [];
|
else [];
|
||||||
# same as intersectLists but takes an array of lists to intersect instead of just two
|
# same as intersectLists but takes an array of lists to intersect instead of just two
|
||||||
intersectManyLists = l:
|
intersectManyLists = l:
|
||||||
if lib.length l == 0 then []
|
if length l == 0 then []
|
||||||
else if lib.length l == 1 then lib.head l
|
else if length l == 1 then head l
|
||||||
else lib.intersectLists (lib.head l) (intersectManyLists (lib.tail l));
|
else intersectLists (head l) (intersectManyLists (tail l));
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib // lib.strings // builtins // utils
|
lib // lib.strings // builtins // utils
|
Loading…
x
Reference in New Issue
Block a user