about summary refs log tree commit diff
path: root/tests/lang/lib.nix
blob: f888453ffbea47a6e0976c5ac3950f68d6135073 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
rec {

  fold = op: nul: list:
    if list == []
    then nul
    else op (builtins.head list) (fold op nul (builtins.tail list));

  concat =
    fold (x: y: x + y) "";

  flatten = x:
    if builtins.isList x
    then fold (x: y: (flatten x) ++ y) [] x
    else [x];

  sum = fold (x: y: builtins.add x y) 0;

}