Last active
October 24, 2018 10:25
-
-
Save pwm/5245bfb1f42f0df68d4237580e9880d1 to your computer and use it in GitHub Desktop.
Compose (unary) functions
This file contains 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 | |
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