Created
February 13, 2018 19:48
-
-
Save webbower/1bf30bd2c5121b8cf07981fbd6df87a6 to your computer and use it in GitHub Desktop.
Functional utilities a la 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 pipe(...$fns) { | |
return function($x) use ($fns) { | |
return array_reduce( | |
$fns, | |
function($acc, $fn) { return $fn($acc); }, | |
$x | |
); | |
}; | |
} | |
function flip($fn) { | |
return function($a, $b, ...$args) use ($fn) { | |
return $fn($b, $a, ...$args); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment