mirror of
https://github.com/NixOS/nix
synced 2025-07-07 18:31:49 +02:00
* Builtin functions head' and
tail' to return the head and tail of
list. Useful for lots of things, such as implementing a fold function (see NIX-30, example is in tests/lang/eval-okay-list.nix).
This commit is contained in:
parent
8a1ab709a4
commit
c02a44183f
3 changed files with 39 additions and 0 deletions
1
tests/lang/eval-okay-list.exp
Normal file
1
tests/lang/eval-okay-list.exp
Normal file
|
@ -0,0 +1 @@
|
|||
Str("foobarblatest")
|
13
tests/lang/eval-okay-list.nix
Normal file
13
tests/lang/eval-okay-list.nix
Normal file
|
@ -0,0 +1,13 @@
|
|||
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) "";
|
||||
|
||||
body = concat ["foo" "bar" "bla" "test"];
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue