Ejemplo n.º 1
0
 /**
  * This method subscribes a listener.
  *
  * @access public
  * @static
  * @param IHashMap\Type $xs                                 the left operand
  * @param ITuple\Type $entry                                a tuple containing the key and listener
  * @return IHashMap\Type                                    the map
  */
 public static function subscribe(IHashMap\Type $xs, ITuple\Type $entry) : IHashMap\Type
 {
     $k = $entry->first();
     $ys = $xs->__hasKey($k) ? $xs->item($k) : ILinkedList\Type::empty_();
     $ys = ILinkedList\Module::append($ys, $entry->second());
     $zs = IHashMap\Module::putEntry($xs, ITuple\Type::box2($k, $ys));
     return $zs;
 }
Ejemplo n.º 2
0
 /**
  * This method tests the "or" method.
  *
  * @dataProvider data_or
  */
 public function test_or(array $provided, array $expected)
 {
     $p0 = ILinkedList\Type::make($provided[0], '\\Saber\\Data\\IBool\\Type');
     $r0 = ILinkedList\Module::or_($p0);
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $r0);
     $this->assertSame($e0, $r0->unbox());
 }
Ejemplo n.º 3
0
 /**
  * This method returns the option as a linked list.
  *
  * @access public
  * @static
  * @param IOption\Type $xs                                  the operand
  * @return ILinkedList\Type                                 the option as a linked list
  */
 public static function toLinkedList(IOption\Type $xs) : ILinkedList\Type
 {
     return $xs->__isDefined() ? ILinkedList\Type::cons($xs->item()) : ILinkedList\Type::nil();
 }
Ejemplo n.º 4
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->ys->__isEmpty();
 }
Ejemplo n.º 5
0
 /**
  * This method returns the collection as a linked list.
  *
  * @access public
  * @static
  * @param IString\Type $xs                                  the operand
  * @return ILinkedList\Type                                 the collection as a linked list
  */
 public static function toLinkedList(IString\Type $xs) : ILinkedList\Type
 {
     $length = $xs->length();
     $zs = ILinkedList\Type::nil();
     for ($i = IInt32\Module::decrement($length); IInt32\Module::ge($i, IInt32\Type::zero())->unbox(); $i = IInt32\Module::decrement($i)) {
         $zs = ILinkedList\Type::cons($xs->item($i), $zs);
     }
     return $zs;
 }
Ejemplo n.º 6
0
 /**
  * This method creates a list of "n" length with every item set to the given object.
  *
  * @access public
  * @static
  * @param Core\Type $x                                      the object to be replicated
  * @param IInt32\Type $n                                    the number of times to replicate
  * @return ILinkedList\Type                                 the collection
  */
 public static function replicate(Core\Type $x, IInt32\Type $n) : ILinkedList\Type
 {
     if ($n->unbox() <= 0) {
         return ILinkedList\Type::nil();
     }
     return ILinkedList\Type::cons($x, ILinkedList\Type::replicate($x, IInt32\Module::decrement($n)));
 }
Ejemplo n.º 7
0
 /**
  * This method tests the "toString" method.
  *
  * @dataProvider data_toString
  */
 public function test_toString(array $provided, array $expected)
 {
     $this->markTestIncomplete();
     $p0 = ILinkedList\Type::make($provided[0])->toString();
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Ejemplo n.º 8
0
 /**
  * This method returns the hash map as a linked list.
  *
  * @access public
  * @static
  * @param IHashMap\Type $xs                                 the hash map
  * @return ILinkedList\Type                                 the hash map as a linked list
  */
 public static function toLinkedList(IHashMap\Type $xs) : ILinkedList\Type
 {
     $zs = ILinkedList\Type::nil();
     $xi = IHashMap\Module::iterator($xs);
     foreach ($xi as $x) {
         $zs = ILinkedList\Type::cons($x, $zs);
     }
     return $zs;
 }
Ejemplo n.º 9
0
 /**
  * This method tests the "toLinkedList" method.
  *
  * @dataProvider data_toLinkedList
  */
 public function test_toLinkedList(array $provided, array $expected)
 {
     $p0 = ILinkedList\Module::toLinkedList(ILinkedList\Type::make($provided[0], '\\Saber\\Data\\IInt32\\Type'));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $p0);
     $this->assertSame($e0, $p0->unbox(1));
 }
Ejemplo n.º 10
0
 /**
  * This method returns the either as a linked list.
  *
  * @access public
  * @final
  * @return ILinkedList\Type                                 the either as a linked list
  */
 public final function toLinkedList() : ILinkedList\Type
 {
     return $this->either->__isLeft() ? ILinkedList\Type::cons($this->either->item()) : ILinkedList\Type::nil();
 }
Ejemplo n.º 11
0
 /**
  * This method returns the collection as a linked list.
  *
  * @access public
  * @static
  * @param IArrayList\Type $xs                               the operand
  * @return ILinkedList\Type                                 the collection as a linked list
  */
 public static function toLinkedList(IArrayList\Type $xs) : ILinkedList\Type
 {
     return IArrayList\Module::foldLeft($xs, function (ILinkedList\Type $c, Core\Type $x) {
         return ILinkedList\Module::append($c, $x);
     }, ILinkedList\Type::empty_());
 }
Ejemplo n.º 12
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param ILinkedList\Type $xs                              the left operand
  * @param ILinkedList\Type $ys                              the right operand
  * @return ITrit\Type                                       the order as to whether the left
  *                                                          operand is less than, equals to,
  *                                                          or greater than the right operand
  */
 public static function compare(ILinkedList\Type $xs, ILinkedList\Type $ys) : ITrit\Type
 {
     for ($as = $xs, $bs = $ys; !$as->__isEmpty() && !$bs->__isEmpty(); $as = $as->tail(), $bs = $bs->tail()) {
         $r = $as->head()->compare($bs->head());
         if ($r->unbox() != 0) {
             return $r;
         }
     }
     return ITrit\Type::box($xs->__length() <=> $ys->__length());
 }