array_reduce 实现 pipeline

  • Post author:
  • Post published:11月 4, 2019
  • Post category:PHP
  • Post comments:0评论
data[] = $value;
    }
}

function carry() {
    return function ($prex,$value) {
        return function ($request) use ($prex,$value) {
            $request->run($value);
            $prex($request);
            return $request;
        };
    };
}

$init = 0;
$arr = [1,2,3];
$request = new Request();

$pipeline = array_reduce(
    array_reverse($arr),carry(), (function ($request) use ($init) {
            $request->run($init);
    })
);

$request = $pipeline($request);
var_dump($request);

发表评论