示例#1
0
 /**
  * This method returns a list of values matching the specified key.
  *
  * @access public
  * @static
  * @param IArrayList\Type $xss                              the array list to be processed
  * @param Core\Type $k                                      the key associated with value to be
  *                                                          plucked
  * @return IArrayList\Type                                  a list of values matching the specified
  *                                                          key
  */
 public static function pluck(IArrayList\Type $xss, Core\Type $k) : IArrayList\Type
 {
     return IArrayList\Module::foldLeft($xss, function (IArrayList\Type $ys, IMap\Type $xs) use($k) : IArrayList\Type {
         if ($xs->__hasKey($k)) {
             return IArrayList\Module::append($ys, $xs->item($k));
         }
         return $ys;
     }, IArrayList\Type::empty_());
 }
示例#2
0
 /**
  * This method tests the "append" method.
  *
  * @dataProvider data_append
  */
 public function test_append(array $provided, array $expected)
 {
     $p0 = IArrayList\Type::make($provided[0], '\\Saber\\Data\\IInt32\\Type');
     $p1 = IInt32\Type::box($provided[1]);
     $r0 = IArrayList\Module::append($p0, $p1);
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IArrayList\\Type', $r0);
     $this->assertSame($e0, $r0->unbox(1));
 }
示例#3
0
 /**
  * This method returns the list as an array.
  *
  * @access public
  * @static
  * @param ILinkedList\Type $xs                              the operand
  * @return IArrayList\Type                                  the list as an array list
  */
 public static function toArrayList(ILinkedList\Type $xs) : IArrayList\Type
 {
     return ILinkedList\Module::foldLeft($xs, function (IArrayList\Type $c, Core\Type $x) {
         return IArrayList\Module::append($c, $x);
     }, IArrayList\Type::empty_());
 }