示例#1
0
 /**
  * This method tests the "iterator" method.
  */
 public function test_iterator()
 {
     $p0 = IOption\Type::some(IInt32\Type::zero());
     $e0 = array(0);
     $this->assertInstanceOf('\\Saber\\Data\\IOption\\Some\\Type', $p0);
     $this->assertSame(count($e0), $p0->__size());
     $p1 = IOption\Module::iterator($p0);
     $e1 = 0;
     $this->assertInstanceOf('\\Saber\\Data\\IOption\\Iterator', $p1);
     foreach ($p1 as $i => $item) {
         $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $i);
         $this->assertSame($e1, $i->unbox());
         $this->assertInstanceOf('\\Saber\\Core\\Type', $item);
         $this->assertSame($e0[$e1], $item->unbox());
         $e1++;
     }
 }
示例#2
0
 /**
  * This method returns whether the iterator is still valid.
  *
  * @access public
  * @final
  * @return bool                                             whether there are more objects
  */
 public final function valid() : bool
 {
     return $this->i->unbox() < $this->xs->__size();
 }
示例#3
0
 /**
  * This method compares the specified object with the current object for order.
  *
  * @access public
  * @static
  * @param IOption\Type $xs                                  the left operand
  * @param IOption\Type $ys                                  the object to be compared
  * @return ITrit\Type                                       whether the current object is less than,
  *                                                          equal to, or greater than the specified
  *                                                          object
  */
 public static function compare(IOption\Type $xs, IOption\Type $ys) : ITrit\Type
 {
     $x = $xs->__isDefined();
     $y = $ys->__isDefined();
     if (!$x && $y) {
         return ITrit\Type::negative();
     }
     if (!$x && !$y) {
         return ITrit\Type::zero();
     }
     if ($x && !$y) {
         return ITrit\Type::positive();
     }
     $x = $xs->item();
     $y = $ys->item();
     if ($x === null && $y !== null) {
         return ITrit\Type::negative();
     }
     if ($x === null && $y === null) {
         return ITrit\Type::zero();
     }
     if ($x !== null && $y === null) {
         return ITrit\Type::positive();
     }
     if ($x instanceof Core\Comparable\Type) {
         return call_user_func_array(array($x, 'compare'), array($y));
     }
     return IString\Module::compare(Core\Module::hashCode($x), Core\Module::hashCode($y));
 }
示例#4
0
 /**
  * This method returns an option using the tail for the boxed object.
  *
  * @access public
  * @static
  * @param IString\Type $xs                                  the left operand
  * @return IOption\Type                                     the option
  */
 public static function tailOption(IString\Type $xs) : IOption\Type
 {
     return $xs->__isEmpty() ? IOption\Type::none() : IOption\Type::some($xs->tail());
 }
示例#5
0
 /**
  * This method tests the "toString" method.
  *
  * @dataProvider data_toString
  */
 public function test_toString(array $provided, array $expected)
 {
     $p0 = IOption\Type::some(IInt32\Type::box($provided[0]))->toString();
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
示例#6
0
 /**
  * This method returns the either as an option.
  *
  * @access public
  * @final
  * @return IOption\Type                                     the either as an option
  */
 public final function toOption() : IOption\Type
 {
     return $this->either->__isLeft() ? IOption\Type::some($this->either->item()) : IOption\Type::none();
 }