src/GeneratorCollection.php
public function takeLast(int $count)
    {
        return $this->wrap(function (Iterator $data) use ($count) {
            // From the end of the collection
            $limit = max(0, $count);
            $chunk = [];

            foreach ($data as $key => $datum) {
                $chunk[] = [$key, $datum];
                if (count($chunk) > $limit) {
                    array_shift($chunk);
                }
            }

            foreach ($chunk as $item) {
                [$key, $datum] = $item;
                yield $key => $datum;
            }
        });
    }
public function takeLast(int $count)
    {
        return $this->wrap(function (Iterator $data) use ($count) {
            // From the end of the collection
            $limit = max(0, $count);
            $chunk = [];

            foreach ($data as $key => $datum) {
                $chunk[] = [$key, $datum];
                if (count($chunk) > $limit) {
                    array_shift($chunk);
                }
            }

            foreach ($chunk as $item) {
                [$key, $datum] = $item;
                yield $key => $datum;
            }
        });
    }
public function takeLast ( int $ count ) { return $ this -> wrap ( function ( Iterator $ data ) use ( $ count ) { // From the end of the collection $ limit = max ( 0 , $ count ) ; $ chunk = [ ] ; foreach ( $ data as $ key => $ datum ) { $ chunk [ ] = [ $ key , $ datum ] ; if ( count ( $ chunk ) > $ limit ) { array_shift ( $ chunk ) ; } } foreach ( $ chunk as $ item ) { [ $ key , $ datum ] = $ item ; yield $ key => $ datum ; } } ) ; }
Take items from the end of the collection

@param int $count
@return \Buttress\Collection\CollectionInterface
Take items from the end of the collection