public function testZipWith() { $f = function ($a, $b) { return $a . $b; }; $concat = P::compose(['P', 'toArray'], P::zipWith($f)); $concatOneTwo = P::zipWith($f, [1, 2]); $this->assertEquals(['1a', '2b'], P::toArray(P::zipWith($f, [1, 2], ['a', 'b']))); $this->assertEquals(['1a', '2b'], $concat([1, 2], ['a', 'b'])); $this->assertEquals(['1a', '2b'], P::toArray($concatOneTwo(['a', 'b']))); $a = function () { (yield 'a'); (yield 'b'); }; $this->assertEquals(['1a', '2b'], P::toArray(P::zipWith($f, [1, 2], $a()))); $this->assertEquals(['1a', '2b'], $concat([1, 2], $a())); }
$applyTax(6.0); //-> Closure $applyTax(6.0, 100); //-> 106 $applyTax(6.0)(100); //-> 106 // $total = P::compose($currency('USD'), $applyTax(6.0), 'P::sum'); // $total([10.95, 16.99, 25.99]); //-> USD 57.1658 // function findUserById($id) { // //... // return Option::fromValue($user); // } // $userOpt = Option::fromValue(findUserById(10)); //-> Option(Option(User)) // $userOpt->flatMap(P::prop('address'))->map(P::prop('country'))->get(); $a = function () { (yield 1); (yield 3); }; $modulo = function ($number) { return $number % 2; }; $modded = P::toArray(P::map($modulo, $a())); print_r($modded); // composition with currying $input = 'A complex system that works is invariably found to have evolved from a simple system that worked'; $explodeOnSpace = P::curry2('explode')(' '); $countWords = P::compose('count', $explodeOnSpace); $countWords($input); //-> 17