コード例 #1
0
ファイル: pipeTest.php プロジェクト: rkgladson/PHPixme
 public function test_return()
 {
     $this->assertInstanceOf(Closure, P\pipe('array_reverse', 'json_encode'), 'pipe should return a closure');
     $this->assertInstanceOf(Closure, P\combine('array_reverse'), 'pipe should be a curried function');
     $array = [1, 2, 3];
     $this->assertEquals(json_encode(array_reverse($array)), P\pipe('array_reverse')->__invoke('json_encode')->__invoke($array), 'pipe should be able to chain the outputs to produce hof results');
     $this->assertEquals(json_decode(json_encode(array_reverse($array))), P\pipe('array_reverse', 'json_encode', 'json_decode')->__invoke($array), 'pipe should be able to handle more than two functions in the chain');
 }
コード例 #2
0
ファイル: demo.php プロジェクト: rkgladson/PHPixme
    $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>
    <p>
        <?php 
$output = call_user_func_array($quaternary($testFn), testData);
?>