Skip to content

Instantly share code, notes, and snippets.

@pwm
Last active October 24, 2018 10:25
Show Gist options
  • Save pwm/5245bfb1f42f0df68d4237580e9880d1 to your computer and use it in GitHub Desktop.
Save pwm/5245bfb1f42f0df68d4237580e9880d1 to your computer and use it in GitHub Desktop.
Compose (unary) functions
<?php
declare(strict_types=1);
final class Compose
{
public static function these(Closure ...$closures): Closure
{
return array_reduce($closures, function (Closure $composed, Closure $f): Closure {
return function ($x) use ($f, $composed) {
return $f($composed($x));
};
}, function ($x) { return $x; });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment