The OpenD Programming Language

partial

Partially applies fun by tying its first argument to arg.

template partial(alias fun, alias arg)
static if(isSomeFunctor || __traits(isTemplate, fun))
partial
(
Ts...
)
()

Parameters

fun

A callable

arg

The first argument to apply to fun

Return Value

A new function which calls fun with arg plus the passed parameters.

Examples

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);

Meta