Ejemplo n.º 1
0
 public function test_scenario_tupleMaker($array = [1, 2, 3, 4])
 {
     // Test to see if we can fix array_map through starling to get the key with the value
     $kvTupple = function ($v, $k) {
         return [$k, $v];
     };
     $kvMap = P\curry(3, P\ternary('array_map'))->__invoke($kvTupple);
     $this->assertEquals(array_map($kvTupple, $array, array_keys($array)), P\S($kvMap, 'array_keys')->__invoke($array));
 }
Ejemplo n.º 2
0
 public function test_with_placeholder()
 {
     $equivlentArray5 = [1, 2, 3, 4, 5];
     $equivlentArray7 = [1, 2, 3, 4, 5, 6, 7];
     $getArgs = function () {
         return func_get_args();
     };
     $this->assertEquals(P\curry(5, $getArgs)->__invoke(1, P\_(), 3, P\_(), 5)->__invoke(2)->__invoke(4), $equivlentArray5, 'When within, the placeholders in Curry should be filled in one by one.');
     $this->assertEquals(P\curry(5, $getArgs)->__invoke(P\_(), P\_(), 3, 4, 5)->__invoke(1, 2), $equivlentArray5, 'When using placeholders with curry, it should still be able to have a varadic follow up.');
     $this->assertEquals(P\curry(5, $getArgs)->__invoke(P\_(), P\_(), P\_(), P\_(), 5, 6)->__invoke(1, P\_(), P\_(), P\_(), 7)->__invoke(2, 3, 4), $equivlentArray7, 'The function should be able to exceed its arity');
 }
Ejemplo n.º 3
0
use PHPixme as P;
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>