Skip to content

Instantly share code, notes, and snippets.

@webbower
Created February 13, 2018 19:48
Show Gist options
  • Save webbower/1bf30bd2c5121b8cf07981fbd6df87a6 to your computer and use it in GitHub Desktop.
Save webbower/1bf30bd2c5121b8cf07981fbd6df87a6 to your computer and use it in GitHub Desktop.
Functional utilities a la PHP
<?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