11 lines
299 B
Nix
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))
|