Пример #1
0
 public function testSubtract()
 {
     $minus = P::flip('P::subtract', 2);
     $minus7 = $minus(7);
     $this->assertEquals(1, P::subtract(8, 7));
     $this->assertEquals(1, $minus7(8));
 }
Пример #2
0
 /**
  * @return callable
  */
 public static function converge()
 {
     $args = func_get_args();
     /**
      * Accepts a converging function and a list of branching functions and returns a new function. When invoked, this new function is applied to some arguments, each branching function is applied to those same arguments. The results of each branching function are passed as arguments to the converging function to produce the return value.
      *
      * @category Function
      *
      * @param callable $conv  The converging function
      * @param array    $funcs List of branching functions
      *
      * @return callable
      * @throws Exception
      */
     $_converge = function ($conv, $funcs) {
         Exception::assertCallable($conv);
         Exception::assertList($funcs);
         return function () use($conv, $funcs) {
             $args = func_get_args();
             $flipped_apply = P::flip('P::apply', 2);
             $applyItemsOverFunctions = self::compose('P::toArray', self::map($flipped_apply($args)));
             return self::apply($conv, $applyItemsOverFunctions($funcs));
         };
     };
     return call_user_func_array(self::curry2($_converge), $args);
 }