Пример #1
0
 /**
  * @param \Traversable $iterator
  * @param int $repeat
  */
 public function __construct(Traversable $iterator, $repeat)
 {
     parent::__construct($appendIterator = new AppendIterator());
     $appendIterator->append($iterator);
     if (!is_int($repeat) || $repeat < 1) {
         throw new InvalidArgumentException('Argument #2 passed to constructor should be integer greater than 1');
     }
     Itertools\repeat($repeat - 1, function () use($appendIterator, $iterator) {
         $appendIterator->append($iterator);
     });
 }
Пример #2
0
<?php

include __DIR__ . '/../vendor/autoload.php';
use WallaceMaxters\Itertools;
use WallaceMaxters\Itertools\Iterators\RepeatIterator;
$time = microtime(true);
$range = null;
Itertools\repeat(100, function ($i) use(&$range) {
    iterator_to_array($range = new Itertools\Range(1, 1000));
});
$repeat = RepeatIterator::fromArray(['a', 'b', 'c'], 2);
foreach ($repeat as $key => $value) {
    echo $key, ' => ', $value, ' position: ', $repeat->getPosition(), PHP_EOL;
}