forked from lix-project/lix
d315210612
With this primitive, a list-flattening function can be implemented (NIX-55, example is in tests/lang/eval-okay-flatten.nix).
20 lines
349 B
Nix
20 lines
349 B
Nix
let {
|
|
|
|
fold = op: nul: list:
|
|
if list == []
|
|
then nul
|
|
else op (builtins.head list) (fold op nul (builtins.tail list));
|
|
|
|
concat =
|
|
fold (x: y: x + y) "";
|
|
|
|
flatten = x:
|
|
if builtins.isList x
|
|
then fold (x: y: (flatten x) ++ y) [] x
|
|
else [x];
|
|
|
|
l = ["1" "2" ["3" ["4"] ["5" "6"]] "7"];
|
|
|
|
body = concat (flatten l);
|
|
}
|