Example #1
0
 function testCycle()
 {
     $colors = new \ArrayIterator(["A", "B", "C", "D"]);
     $it = itertools\slice(itertools\cycle($colors), 0, 10);
     $list = [];
     foreach ($it as $val) {
         $list[] = $val;
     }
     $this->assertEquals(["A", "B", "C", "D", "A", "B", "C", "D", "A", "B"], $list);
 }
Example #2
0
 /**
  * Return multi dimensional array for $n most common elements and their
  * counts from the most to the least. If $n is null, then it return all
  * element counts.
  *
  * @param  int $n
  * @return array
  */
 public function mostCommon($n = null)
 {
     $list = sort_by($this->items(), function ($elem) {
         return -$elem[1];
     });
     if ($n !== null) {
         return iterator_to_array(slice($list, 0, $n));
     }
     return $list;
 }
Example #3
0
 function slice($offset, $count = -1)
 {
     $this->iterator = itertools\slice($this->iterator, $offset, $count);
     return $this;
 }