CASCADE/functions/flatten.nix

12 lines
359 B
Nix
Raw Normal View History

2022-09-27 16:07:58 +00:00
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