a function taking at least one argument
A single parameter callable object
int f(int x, int y, int z) { return x + y + z; } auto cf = curry!f; auto cf1 = cf(1); auto cf2 = cf(2); assert(cf1(2)(3) == f(1, 2, 3)); assert(cf2(2)(3) == f(2, 2, 3));
1 //works with callable structs too 2 struct S 3 { 4 int w; 5 int opCall(int x, int y, int z) 6 { 7 return w + x + y + z; 8 } 9 } 10 11 S s; 12 s.w = 5; 13 14 auto cs = curry(s); 15 auto cs1 = cs(1); 16 auto cs2 = cs(2); 17 18 assert(cs1(2)(3) == s(1, 2, 3)); 19 assert(cs1(2)(3) == (1 + 2 + 3 + 5)); 20 assert(cs2(2)(3) ==s(2, 2, 3));
Takes a function of (potentially) many arguments, and returns a function taking one argument and returns a callable taking the rest. f(x, y) == curry(f)(x)(y)