Skip to content

Instantly share code, notes, and snippets.

@trowski
Last active May 26, 2021 14:30
Show Gist options
  • Save trowski/fdbf2ee51ce183dceb6a8025604384ad to your computer and use it in GitHub Desktop.
Save trowski/fdbf2ee51ce183dceb6a8025604384ad to your computer and use it in GitHub Desktop.
  • ? represents a single, required param in the partial closure returned, even if ? maps to an optional argument.
  • ... indicates additional arguments to the partial closure should be passed through.
function f(int $x, int $y = 0, int $z = 0) {}

f(...); // No bound params, pass through all params.
f(?, ...); // No bound params, 1 param required to partial, pass through all params.
f(?, ?); // No bound params, 2 params required to partial, no pass through.
f(?); // No bound params, 1 param required to partial, no pass through.
f(1, ...); // First param bound, pass through all params.
f(1, ?); // First param bound, 1 param required to partial.
f(?, 2, ?); // Second param bound, 2 params required to partial.
f(?, ?, 1); // Third param bound, 2 params required to partial.
f(?, 2, z: 3); // Second and third param bound, 1 param required to partial.
f(1, ?, z: 3); // First and third param bound, 1 param required to partial.
f(?, z: 3); // Third param bound, 1 param required to partial.
f(1, ..., z: 3); // First and third param bound, all argument passed through (skipping bound slots).
f(1, ?, y: 2); // Error, named param overrides positional.
f(?, x: 1); // Error, named param overrides positional.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment