diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-09-22T15·29+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-09-22T15·29+0000 |
commit | 2ab4bc44c780d2e28647f7559664675b756f38b9 (patch) | |
tree | 39ecb0e001cf6c031e15b0246559b3f8f7a06ed9 /tests/lang/lib.nix | |
parent | d315210612a8d5eb52654407903544b72222130b (diff) |
* Builtin function `add' to add integers.
* Put common test functions in tests/lang/lib.nix.
Diffstat (limited to 'tests/lang/lib.nix')
-rw-r--r-- | tests/lang/lib.nix | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/lang/lib.nix b/tests/lang/lib.nix new file mode 100644 index 000000000000..f888453ffbea --- /dev/null +++ b/tests/lang/lib.nix @@ -0,0 +1,18 @@ +rec { + + 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]; + + sum = fold (x: y: builtins.add x y) 0; + +} |