21 lines
750 B
Nix
21 lines
750 B
Nix
{ lib, ... }:
|
|
with lib;
|
|
with builtins; rec {
|
|
readLines = f: init (filter isString (split "\n" (readFile f)));
|
|
reSplit = re: s: filter isString (split re s);
|
|
matchAll = re: s: filter isList (split re s);
|
|
splitWhitespace = reSplit "[[:space:]]+";
|
|
abs = i: if i >= 0 then i else i * -1;
|
|
delta = x: y: abs (x - y);
|
|
listSum = foldl' add 0;
|
|
listSumWith = f: l: foldl' add 0 (map f l);
|
|
deleteAt = l: i: (take i l) ++ (drop (i + 1) l);
|
|
eq = x: y: x == y;
|
|
greaterThan = x: y: x > y;
|
|
listRange = l: range 0 ((length l) - 1);
|
|
transpose = l: map (i: map ((flip elemAt) i) l) (listRange (head l));
|
|
invert = f: x: !(f x);
|
|
elemAtMid = l: elemAt l ((length l) / 2);
|
|
removeAll = rl: (flip pipe) (map remove rl);
|
|
pipe' = flip pipe;
|
|
}
|