Ejemplo n.º 1
0
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;
?>
 &mdash;map($makeView)&mdash;reduce&rightarrow;
        <?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;
?>
 &mdash;map2x&mdash;filterWith(_ mod 8 = 0)&mdash;values&rightarrow;
        <?php 
echo json_encode(array_values(P\flip('array_filter')->__invoke(function ($value) {
    return $value % 8 === 0;
})->__invoke($mapX2(testData))));
Ejemplo n.º 2
0
 /**
  * @dataProvider scenarioProvider
  */
 public function test_scenario($arrayLike, $action, $expected)
 {
     $this->assertEquals($expected, P\reduce($action, $arrayLike));
 }