Last active
September 17, 2016 14:45
-
-
Save slifin/ebfb3bb084e6633d94fb915e65202791 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Data type to signify a placeholder. | |
| */ | |
| class Placeholder {} | |
| class_alias('Placeholder', '_'); | |
| /** | |
| * Implements partial application with placeholder support. | |
| * | |
| * Similar to http://underscorejs.org/#partial. | |
| * | |
| * @param Function|callable $fn | |
| * The function to apply to. | |
| * @param array $start | |
| * The starting arguments to apply. | |
| * | |
| * @return callable | |
| * Partially applied function. | |
| */ | |
| function partial(callable $fn, ...$start) { | |
| return function (...$args) use ($fn, $start) { | |
| return @$fn(...array_map(function ($v) use (&$args) { | |
| return $v instanceof _ ? array_shift($args) : $v; | |
| }, $start)); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment