public function test_return() { $getArgs = function () { return func_get_args(); }; $this->assertInstanceOf(Closure, P\flip($getArgs), 'Flip should return a closure'); $this->assertEquals([2, 1, 3, 4, 5], P\flip($getArgs)->__invoke(1, 2, 3, 4, 5), 'Flip should flip the first two arguments'); $this->assertInstanceOf(Closure, P\flip($getArgs)->__invoke(1), 'Flip partially applied should return a closure'); $this->assertEquals([2, 1, 3, 4, 5], P\flip($getArgs)->__invoke(1)->__invoke(2, 3, 4, 5), 'Flip partially applied should return the flipped arguments'); }
public function test_return($array = [1, 2, 3, 4]) { $this->assertInstanceOf(Closure, P\reduceRight(P\I), 'when partially applied should return a closure'); $this->assertEquals($array[count($array) - 1], P\reduceRight(P\I)->__invoke($array), 'An idiot applied should always return the last value'); $this->assertEquals($array[0], P\reduceRight(P\flip(P\I), $array), 'The flipped idiot applied should always return the first value'); }
public function test_return($value = 1, $array = [1, 2, 3, 4]) { $this->assertInstanceOf(Closure, P\fold(P\I, $value), 'when partially applied should return a closure'); $this->assertEquals($value, P\fold(P\I, $value)->__invoke($array), 'An idiot applied should always return the start value'); $this->assertEquals($array[count($array) - 1], P\fold(P\flip(P\I), $value, $array), 'The flipped idiot applied should always return the last unless empty'); }
</ul> </section> <section> <h2>Thrill as I convert this Hash Array to an array of Tupples!</h2> <p> <?php $tupleMaker = P\S(P\ternary('array_map')->__invoke(function ($val, $key) { return [$key, $val]; }), 'array_keys'); $testDataAsTuple = $tupleMaker(testData); ?> <?php echo $jsonTestData; ?> —$map(x, y -> [y,x])→ <?php echo json_encode($testDataAsTuple); ?> </p> <p>And to show why I picked these numbers</p> <ul> <?php P\flip(P\binary('array_walk'))->__invoke(function ($tuple) { echo "<li>2<sup>{$tuple['0']}</sup> = {$tuple['1']}</li>" . PHP_EOL; }, $testDataAsTuple); ?> </ul> </section> </body> </html>