Пример #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;
 }
Пример #2
0
 /**
  * This method tests the "append" method.
  *
  * @dataProvider data_append
  */
 public function test_append(array $provided, array $expected)
 {
     $p0 = ILinkedList\Type::make($provided[0], '\\Saber\\Data\\IInt32\\Type');
     $p1 = IInt32\Type::box($provided[1]);
     $r0 = ILinkedList\Module::append($p0, $p1);
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $r0);
     $this->assertSame($e0, $r0->unbox(1));
 }
Пример #3
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_());
 }
Пример #4
0
 /**
  * This method returns a linked list of values matching the specified key.
  *
  * @access public
  * @static
  * @param ILinkedList\Type $xss                             the linked list to be processed
  * @param Core\Type $k                                      the key associated with value to be
  *                                                          plucked
  * @return ILinkedList\Type                                 a list of values matching the specified
  *                                                          key
  */
 public static function pluck(ILinkedList\Type $xss, Core\Type $k) : ILinkedList\Type
 {
     return ILinkedList\Module::foldLeft($xss, function (ILinkedList\Type $ys, IMap\Type $xs) use($k) : ILinkedList\Type {
         if ($xs->__hasKey($k)) {
             return ILinkedList\Module::append($ys, $xs->item($k));
         }
         return $ys;
     }, ILinkedList\Type::empty_());
 }