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
|
||||
lib = import <nixpkgs/lib>;
|
||||
utils = rec {
|
||||
inherit lib;
|
||||
utils = with lib; rec {
|
||||
# Passthrough trace for debugging
|
||||
pTrace = v: lib.traceSeq v v;
|
||||
pTrace = v: traceSeq v v;
|
||||
# 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
|
||||
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
|
||||
maxList = lib.foldr lib.max 0;
|
||||
maxList = foldr max 0;
|
||||
# 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
|
||||
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
|
||||
chunksOf = cnt: l:
|
||||
if lib.length l >= cnt then
|
||||
[(lib.take cnt l)] ++ chunksOf cnt (lib.drop cnt l)
|
||||
if length l >= cnt then
|
||||
[(take cnt l)] ++ chunksOf cnt (drop cnt l)
|
||||
else [];
|
||||
# same as intersectLists but takes an array of lists to intersect instead of just two
|
||||
intersectManyLists = l:
|
||||
if lib.length l == 0 then []
|
||||
else if lib.length l == 1 then lib.head l
|
||||
else lib.intersectLists (lib.head l) (intersectManyLists (lib.tail l));
|
||||
if length l == 0 then []
|
||||
else if length l == 1 then head l
|
||||
else intersectLists (head l) (intersectManyLists (tail l));
|
||||
};
|
||||
in
|
||||
lib // lib.strings // builtins // utils
|
Loading…
x
Reference in New Issue
Block a user