Пример #1
0
 /**
  * This method tests the "foldRight" method.
  *
  * @dataProvider data_foldRight
  */
 public function test_foldRight(array $provided, array $expected)
 {
     $p0 = ILinkedList\Type::make($provided[0], '\\Saber\\Data\\IInt32\\Type');
     $p1 = $provided[1];
     $r0 = ILinkedList\Module::foldRight($p0, $p1, IInt32\Type::zero());
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $r0);
     $this->assertSame($e0, $r0->unbox());
 }
Пример #2
0
 /**
  * This method applies a right-fold reduction on the list using the operator function.
  *
  * @access public
  * @static
  * @param ILinkedList\Type $xs                              the left operand
  * @param callable $operator                                the operator function to be used
  * @param Core\Type $initial                                the initial value to be used
  * @return Core\Type                                        the result
  */
 public static function foldRight(ILinkedList\Type $xs, callable $operator, Core\Type $initial) : Core\Type
 {
     $z = $initial;
     if ($xs->__isEmpty()) {
         return $z;
     }
     return $operator($xs->head(), ILinkedList\Module::foldRight($xs->tail(), $operator, $z));
 }