public function resolve(Context $context) { $resolver = function ($r) { return [$r, 'resolve']; }; $composed = call_user_func_array('felpado\\compose', f\reverse(f\map($resolver, $this->resolvers))); return $composed($context); }
/** * f\compose(callable $fn1 [, $fn...]) * * Returns a function that is the composition of the passed functions. * The first function (right to left) receives the passed args, and the rest the result * of the previous function. * * $revUp = f\compose('strtoupper', 'strrev'); * $revUp('hello'); * => OLLEH */ function compose() { $fns = func_get_args(); $compose = function ($composition, $fn) { return function () use($composition, $fn) { return call_user_func($fn, call_user_func_array($composition, func_get_args())); }; }; return f\reduce($compose, f\reverse($fns)); }
/** * @dataProvider provideReverse */ public function testIndexed($exp, $coll) { $this->assertSame($exp, f\reverse($coll)); }