Created
December 13, 2015 22:48
-
-
Save jm42/f19393e7a2216867d0ef to your computer and use it in GitHub Desktop.
Example of partial1 in PHP
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 | |
| function partial1(/* A */ $a, /* (A, B) => C */ callable $f) /* B => C */ { | |
| return function(/* B */ $b) use($a, $f) { | |
| return $f($a, $b); | |
| }; | |
| } | |
| /* A :: String | |
| * B :: String | |
| * C :: Integer */ | |
| $similar_bar = partial1('bar', 'similar_text'); | |
| /** @var $result Integer */ | |
| $result = $similar_bar('baz'); | |
| /* Result is two because 'ba' | |
| * is shared by both strings. */ | |
| assert($result == 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment