Fusonic\Linq\Linq::take PHP Method

take() public method

Returns a specified number of contiguous elements from the start of a sequence
public take ( integer $count ) : Linq
$count integer The number of elements to return.
return Linq A Linq object that contains the specified number of elements from the start.
    public function take($count)
    {
        if ($count == 0) {
            return new Linq([]);
        }
        $innerIterator = $this->iterator;
        if (!$innerIterator instanceof \Iterator) {
            // IteratorIterator wraps $this->iterator because it is Traversable but not an Iterator.
            // (see https://bugs.php.net/bug.php?id=52280)
            $innerIterator = new \IteratorIterator($innerIterator);
        }
        return new Linq(new \LimitIterator($innerIterator, 0, $count));
    }