From 2ab4bc44c780d2e28647f7559664675b756f38b9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 22 Sep 2006 15:29:21 +0000 Subject: * Builtin function `add' to add integers. * Put common test functions in tests/lang/lib.nix. --- tests/lang/lib.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/lang/lib.nix (limited to 'tests/lang/lib.nix') 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; + +} -- cgit 1.4.1