From 5a4bb765a3b82aba683f150d2cceac4f5a9eb5d3 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Thu, 21 Apr 2022 22:42:38 +0000 Subject: [PATCH] Add '28.nix' --- 28.nix | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 28.nix diff --git a/28.nix b/28.nix new file mode 100644 index 0000000..8c9a2f1 --- /dev/null +++ b/28.nix @@ -0,0 +1,11 @@ +with import { }; +let + list = ["a" "b" "a" "c" "d" "a"]; + countA = lib.fold (x: y: if x != "a" then y else y + 1) 0; +in +rec { + example = lib.fold (x: y: x + y) "" ["a" "b" "c"]; #is "abc" + result = countA list; #should be 3 +} + +# fold f z [x_1 x_2 ... x_n] == f x_1 (f x_2 ... (f x_n z)) \ No newline at end of file