Пример #1
0
 public function test_return()
 {
     $countArgs = function () {
         return func_num_args();
     };
     $this->assertInstanceOf(Closure, P\nAry(1), 'nAry should be partially applied');
     $this->assertEquals(1, P\nAry(1)->__invoke($countArgs)->__invoke(1, 2, 3), 'nAry Partially applied should still produce a wrapped function that eats arguments');
     $this->assertInstanceOf(Closure, P\nAry(1, $countArgs), 'nAry fully applied should produce a closure');
     $this->assertEquals(1, P\nAry(1, $countArgs)->__invoke(1, 2, 3, 4), 'fully applied should still work the same as partially applied, eating arguments');
 }
Пример #2
0
const BR = '<br/>' . PHP_EOL;
const testData = [1, 2, 4, 8, 16];
$jsonTestData = json_encode(testData);
$testFn = function (...$args) {
    $output = implode(', ', $args);
    echo '$testFn received: ' . $output . BR;
    return $output;
};
$timesTwo = function ($value) {
    return $value * 2;
};
$stringify = function ($value) {
    return "'{$value}'";
};
$curry2 = P\curry(2);
$quaternary = P\nAry(4);
$map = P\binary('array_map');
$mapX2 = $map($timesTwo);
$joinComma = P\binary('implode')->__invoke(', ');
$makeView = P\combine($stringify, $timesTwo);
?>
<h1>Time to fix PHP!</h1>
<p>
    Behold! There is nothing up my sleeves!<br>
    <?php 
echo $jsonTestData;
?>
</p>

<section>
    <h2>Testing Quaternary!</h2>