echo P\fold(function ($output, $value) { return $output ? "{$output}, {$value}" : $value; }, '', $map($makeView, testData)); ?> </p> </section> <section> <h2>Again, but now using reduce to produce the join!</h2> <p> <?php echo $jsonTestData; ?> —map($makeView)—reduce→ <?php echo P\reduce(function ($output, $value) { return "{$output}, {$value}"; }, $map($makeView, testData)); ?> </p> </section> <section> <h2>Watch in <i>horror</i> as I flip a native function! array_filter</h2> <p> <?php echo $jsonTestData; ?> —map2x—filterWith(_ mod 8 = 0)—values→ <?php echo json_encode(array_values(P\flip('array_filter')->__invoke(function ($value) { return $value % 8 === 0; })->__invoke($mapX2(testData))));
/** * @dataProvider scenarioProvider */ public function test_scenario($arrayLike, $action, $expected) { $this->assertEquals($expected, P\reduce($action, $arrayLike)); }