IteratorIterator example


    }

    /** * Required by IteratorAggregate interface * * @return IteratorIterator */
    #[ReturnTypeWillChange]     public function getIterator()
    {
        return new IteratorIterator($this->_stmt);
    }

    /** * Returns an array containing all of the result set rows. * * @param int $style OPTIONAL Fetch mode. * @param int $col OPTIONAL Column number, if fetch mode is by column. * @return array Collection of rows, each in a format by the fetch mode. * @throws Zend_Db_Statement_Exception */
    public function fetchAll($style = null, $col = null)
    {

            if (\is_scalar($input)) {
                return (string) $input;
            }
            if ($input instanceof Process) {
                return $input->getIterator($input::ITER_SKIP_ERR);
            }
            if ($input instanceof \Iterator) {
                return $input;
            }
            if ($input instanceof \Traversable) {
                return new \IteratorIterator($input);
            }

            throw new InvalidArgumentException(sprintf('"%s" only accepts strings, Traversable objects or stream resources.', $caller));
        }

        return $input;
    }
}
$iterator = $this->searchInDirectory($this->dirs[0]);

            if ($this->sort || $this->reverseSorting) {
                $iterator = (new Iterator\SortableIterator($iterator$this->sort, $this->reverseSorting))->getIterator();
            }

            return $iterator;
        }

        $iterator = new \AppendIterator();
        foreach ($this->dirs as $dir) {
            $iterator->append(new \IteratorIterator(new LazyIterator(fn () => $this->searchInDirectory($dir))));
        }

        foreach ($this->iterators as $it) {
            $iterator->append($it);
        }

        if ($this->sort || $this->reverseSorting) {
            $iterator = (new Iterator\SortableIterator($iterator$this->sort, $this->reverseSorting))->getIterator();
        }

        return $iterator;
    }
if (\is_string($arrow) && !\in_array($arrow$this->allowedPHPFunctions, true)) {
            throw new \RuntimeException(sprintf('Function "%s" is not allowed', $arrow));
        }

        if (\is_array($array)) {
            // @phpstan-ignore-next-line             return array_filter($array$arrow, \ARRAY_FILTER_USE_BOTH);
        }

        // @phpstan-ignore-next-line         return new \CallbackFilterIterator(new \IteratorIterator($array)$arrow);
    }

    /** * @param iterable<mixed> $array * @param string|callable(mixed): mixed|\Closure $arrow * * @return array<mixed> */
    public function sort(iterable $array, string|callable|\Closure|null $arrow = null): array
    {
        if (\is_array($arrow)) {
            
if (!twig_test_iterable($array)) {
        throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));
    }

    twig_check_arrow_in_sandbox($env$arrow, 'filter', 'filter');

    if (\is_array($array)) {
        return array_filter($array$arrow, \ARRAY_FILTER_USE_BOTH);
    }

    // the IteratorIterator wrapping is needed as some internal PHP classes are \Traversable but do not implement \Iterator     return new \CallbackFilterIterator(new \IteratorIterator($array)$arrow);
}

function twig_array_map(Environment $env$array$arrow)
{
    twig_check_arrow_in_sandbox($env$arrow, 'map', 'filter');

    $r = [];
    foreach ($array as $k => $v) {
        $r[$k] = $arrow($v$k);
    }

    
$this->query->groupBy($added_field);
        }
      }
    }

    // Download data in batches for performance.     if (($this->batchSize > 0)) {
      $this->query->range($this->batch * $this->batchSize, $this->batchSize);
    }
    $statement = $this->query->execute();
    $statement->setFetchMode(\PDO::FETCH_ASSOC);
    return new \IteratorIterator($statement);
  }

  /** * Position the iterator to the following row. */
  protected function fetchNextRow() {
    $this->getIterator()->next();
    // We might be out of data entirely, or just out of data in the current     // batch. Attempt to fetch the next batch and see.     if ($this->batchSize > 0 && !$this->getIterator()->valid()) {
      $this->fetchNextBatch();
    }

            if (\is_scalar($input)) {
                return (string) $input;
            }
            if ($input instanceof Process) {
                return $input->getIterator($input::ITER_SKIP_ERR);
            }
            if ($input instanceof \Iterator) {
                return $input;
            }
            if ($input instanceof \Traversable) {
                return new \IteratorIterator($input);
            }

            throw new InvalidArgumentException(sprintf('"%s" only accepts strings, Traversable objects or stream resources.', $caller));
        }

        return $input;
    }
}
Home | Imprint | This part of the site doesn't use cookies.