View source code
Display the source code in std/functional.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.functional.partial

Partially applies fun by tying its first argument to arg.

ReturnType!fun partial(alias fun, alias arg) (
  Parameters!fun[1..__dollar] args2
);

Parameters

NameDescription
fun A callable
arg The first argument to apply to fun

Returns

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

Example

int fun(int a, int b) { return a + b; }
alias fun5 = partial!(fun, 5);
writeln(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.

Authors

Andrei Alexandrescu

License

Boost License 1.0.