Add '28.nix'

master
NaiJi ✨ 2 years ago
parent c30ebe1880
commit 5a4bb765a3

@ -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))
Loading…
Cancel
Save