src/precore/util/Iterators.php
public static function limit(Iterator $iterator, int $limitSize) : Iterator
    {
        Preconditions::checkArgument(0 <= $limitSize);
        return new NoRewindNecessaryLimitIterator($iterator, $limitSize);
    }
public static function limit(Iterator $iterator, int $limitSize) : Iterator
    {
        Preconditions::checkArgument(0 <= $limitSize);
        return new NoRewindNecessaryLimitIterator($iterator, $limitSize);
    }
Creates an iterator returning the first limitSize elements of the given iterator.
If the original iterator does not contain that many elements,
the returned iterator will have the same behavior as the original iterator.

@param Iterator $iterator
@param int $limitSize
@return Iterator
@throws \InvalidArgumentException if $limit is negative