A new function which calls fun with arg plus the passed parameters.
int fun(int a, int b) { return a + b; } alias fun5 = partial!(fun, 5); assert(fun5(6) == 11); // Note that in most cases you'd use an alias instead of a value // assignment. Using an alias allows you to partially evaluate template // functions without committing to a particular type of the function.
// Overloads are resolved when the partially applied function is called // with the remaining arguments. struct S { static char fun(int i, string s) { return s[i]; } static int fun(int a, int b) { return a * b; } } alias fun3 = partial!(S.fun, 3); assert(fun3("hello") == 'l'); assert(fun3(10) == 30);
Partially applies fun by tying its first argument to arg.