Skip to content

Instantly share code, notes, and snippets.

@jm42
Created December 13, 2015 22:48
Show Gist options
  • Save jm42/f19393e7a2216867d0ef to your computer and use it in GitHub Desktop.
Save jm42/f19393e7a2216867d0ef to your computer and use it in GitHub Desktop.
Example of partial1 in PHP
<?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