/** * This method tests the "iterator" method. * * @dataProvider data_iterator */ public function test_iterator(array $provided, array $expected) { $p0 = ILinkedList\Type::make($provided[0], '\\Saber\\Data\\IInt32\\Type'); $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $p0); $this->assertCount(count($e0), $p0->unbox()); $p1 = ILinkedList\Module::iterator($p0); $e1 = 0; $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\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++; } }
/** * This method returns a tuple of two (or more) linked lists after splitting a linked list of * tuple groupings. * * @access public * @static * @param ILinkedList\Type $xss a linked list of tuple groupings * @return ITuple\Type a tuple of two (or more) linked lists */ public static function unzip(ILinkedList\Type $xss) : ITuple\Type { $as = array(); $bs = array(); $xsi = ILinkedList\Module::iterator($xss); foreach ($xsi as $i => $xs) { $as[] = $xs->first(); $bs[] = $xs->second(); } return ITuple\Type::box2(ILinkedList\Type::box($as), ILinkedList\Type::box($bs)); }