You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

11 lines
299 B
Nix

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))