PHPackages                             chh/itertools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. chh/itertools

ActiveLibrary

chh/itertools
=============

Common functional operations for iterators.

v1.0.0(13y ago)72.4k1MITPHPPHP &gt;=5.3.3

Since Jan 8Pushed 12y ago1 watchersCompare

[ Source](https://github.com/CHH/itertools)[ Packagist](https://packagist.org/packages/chh/itertools)[ RSS](/packages/chh-itertools/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (2)Used By (1)

itertools
=========

[](#itertools)

`itertools` aims to bring the support for operations on PHP's iterators to the same level than for arrays.

Install
-------

[](#install)

Install via [composer](http://getcomposer.org):

```
% wget http://getcomposer.org/composer.phar
% php composer.phar require chh/itertools:~1.0

```

Usage
-----

[](#usage)

`itertools` provides a small set of operations via a set of functions. Most functions operate by wrapping an iterator in another iterator. This means that most operations are lazily evaluated, except where it doesn't make sense.

That makes these functions an efficient solution for filtering or mapping:

- Symfony Finder instances
- `PDOStatement` or `Mysqli_Result` (since 5.4.0) objects.
- ORM datasets/collections which implement `\Traversable`.

### `\Traversable itertools\slice(\Traversable $traversable, $start, [$count = -1])`

[](#traversable-itertoolsslicetraversable-traversable-start-count---1)

Wraps the traversable in an iterator, which starts iteration at the given offset `$start`, and stops after yielding `$count` elements. By default, it iterates to the end of the wrapped traversable.

Example:

```
