mirror of
https://github.com/NixOS/nix
synced 2025-07-10 04:43:53 +02:00
* Added a builtin function `isList' to test whether a value is a list.
With this primitive, a list-flattening function can be implemented (NIX-55, example is in tests/lang/eval-okay-flatten.nix).
This commit is contained in:
parent
c02a44183f
commit
d315210612
3 changed files with 29 additions and 0 deletions
1
tests/lang/eval-okay-flatten.exp
Normal file
1
tests/lang/eval-okay-flatten.exp
Normal file
|
@ -0,0 +1 @@
|
|||
Str("1234567")
|
19
tests/lang/eval-okay-flatten.nix
Normal file
19
tests/lang/eval-okay-flatten.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue