1 module beard.fold_left;
2 
3 /// Produces F(Tn, F(.., F(T2, F(A, T1))))
4 template foldLeft(alias F, alias A) {
5     alias A foldLeft;
6 }
7 
8 /// ditto
9 template foldLeft(alias F, alias A, H, T...) {
10     alias foldLeft!(F, F!(A, H), T) foldLeft;
11 }
12 
13 /// Like foldLeft but calls an inner template "add" on the first alias
14 /// as template argument allowing the calling template to store state.
15 template foldLeft2(alias F, T...) {
16     alias foldLeft!(innerFold, F, T) foldLeft2;
17 }
18 
19 /// Helper function.
20 private template innerFold(alias T, U) {
21     alias T.add!U innerFold;
22 }
23 // vim:ts=4 sw=4