Пример #1
0
 public function testPropOf()
 {
     $assoc = ['x' => 100, 'y' => 200, 'z' => 300];
     $this->assertEquals(P::prop('x', $assoc), P::propOf($assoc, 'x'));
 }
Пример #2
0
require_once '../ch08/model/Account.php';
use Model\Account;
use Model\User;
use Rx\Observable;
use Rx\Observer;
// SELECT firstname
// FROM users
// WHERE firstname IS NOT NULL
// ORDER BY firstname DESC
// LIMIT 1;
print_r(P::pipe('\\Model\\User::query', P::map(P::prop('firstname')), P::filter(function ($n) {
    return !empty($n);
}), 'P::reverse', P::take(1))());
P::compose(P::take(1), 'P::reverse', P::filter(function ($n) {
    return !empty($n);
}), P::map(P::prop('firstname')), '\\Model\\User::query')();
// PHP Warning:  f() expects
// at least 2 parameters, 1 given
// $format = P::compose('addExclamation', $repeat(2), 'strtoupper');
// $format('Hello World'); //-> HELLO WORLD HELLO WORLD!
$applyTax = P::curry2(function ($rate, $amount) {
    return $amount + $amount * ($rate / 100);
});
$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