add some support functions
This commit is contained in:
parent
429f846f9b
commit
a57f4b0094
11
functions/flatten.nix
Normal file
11
functions/flatten.nix
Normal file
|
@ -0,0 +1,11 @@
|
|||
with builtins;
|
||||
let flatten-once = foldl' (x: y: x ++ (if isList y then y else [y])) []; # curried. takes a list as final arg.
|
||||
flatten-many' = flatten-many': l:
|
||||
let flattened = flatten-once l;
|
||||
in
|
||||
if flattened == l
|
||||
then l
|
||||
else flatten-many' flatten-many' flattened;
|
||||
flatten-many = flatten-many' flatten-many';
|
||||
in
|
||||
flatten-many
|
12
functions/join-string.nix
Normal file
12
functions/join-string.nix
Normal file
|
@ -0,0 +1,12 @@
|
|||
with builtins;
|
||||
|
||||
let join' = join': sep: sl:
|
||||
if sl == []
|
||||
then ""
|
||||
else if length sl == 1
|
||||
then head sl
|
||||
else "${head sl}${sep}${join' join' sep (tail sl)}";
|
||||
join = join' join';
|
||||
in
|
||||
|
||||
join
|
3
functions/match-all-flat.nix
Normal file
3
functions/match-all-flat.nix
Normal file
|
@ -0,0 +1,3 @@
|
|||
with import (toString ./.);
|
||||
|
||||
with builtins; pattern: s: flatten (match-all pattern s)
|
1
functions/match-all.nix
Normal file
1
functions/match-all.nix
Normal file
|
@ -0,0 +1 @@
|
|||
with builtins; pattern: s: filter isList (split pattern s)
|
4
functions/name-to-mac.nix
Normal file
4
functions/name-to-mac.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
with import (toString ./.);
|
||||
with builtins;
|
||||
|
||||
elts: name: join-string ":" (take elts (match-all-flat "(..)" (hashString "sha256" name)))
|
11
functions/take.nix
Normal file
11
functions/take.nix
Normal file
|
@ -0,0 +1,11 @@
|
|||
with builtins;
|
||||
|
||||
let take' = take': n: l:
|
||||
if n < 0 then throw "take requires a positive whole number or 0." else
|
||||
if n == 0 || l == []
|
||||
then []
|
||||
else [ (head l) ] ++ (take' take' (n - 1) (tail l));
|
||||
take = take' take';
|
||||
in
|
||||
|
||||
take
|
Loading…
Reference in New Issue
Block a user