Add '28.nix'

This commit is contained in:
NaiJi ✨ 2022-04-21 22:42:38 +00:00
parent c30ebe1880
commit 5a4bb765a3
1 changed files with 11 additions and 0 deletions

11
28.nix Normal file
View File

@ -0,0 +1,11 @@
with import <nixpkgs> { };
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))