Skip to content

Instantly share code, notes, and snippets.

@callistabee
Created September 23, 2014 12:21
Show Gist options
  • Save callistabee/076aa4289bff3d14aa46 to your computer and use it in GitHub Desktop.
Save callistabee/076aa4289bff3d14aa46 to your computer and use it in GitHub Desktop.
php function currying
<?php
function add($x,$y) {
return $x + $y;
}
function curry($fn) {
return function($x) use ($fn) {
return function($y) use ($x, $fn) {
return $fn($x,$y);
};
};
}
$val = curry("add")->__invoke(5)->__invoke(6);
echo "$val\n"; // 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment