PHPackages                             thesebas/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. thesebas/itertools

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

thesebas/itertools
==================

itertools for working with genrators/iterators

1.0.3(8y ago)030MITPHP

Since Nov 4Pushed 8y ago1 watchersCompare

[ Source](https://github.com/thesebas/php-itertools)[ Packagist](https://packagist.org/packages/thesebas/itertools)[ RSS](/packages/thesebas-itertools/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

thesebas/itertools
==================

[](#thesebasitertools)

Tools to work with iterators. [![BUILD STATUS](https://camo.githubusercontent.com/cecb6d1c1a3d8bef35604fece4789a3daa70906b0c94040a7023ca5132bf504f/68747470733a2f2f6170692e7472617669732d63692e6f72672f74686573656261732f7068702d69746572746f6f6c732e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/cecb6d1c1a3d8bef35604fece4789a3daa70906b0c94040a7023ca5132bf504f/68747470733a2f2f6170692e7472617669732d63692e6f72672f74686573656261732f7068702d69746572746f6f6c732e7376673f6272616e63683d6d6173746572) [![Coverage Status](https://camo.githubusercontent.com/fe2c334be51de97ae82fb49e7ac17e6a86f0709265e07f5f0664283521cab457/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f74686573656261732f7068702d69746572746f6f6c732f62616467652e737667)](https://coveralls.io/github/thesebas/php-itertools)

Installation
------------

[](#installation)

`composer require thesebas/itertools`

Usage
-----

[](#usage)

Lest assume we have some generator that yields letters.

```
expect(iterator_to_array(gen(3)))->toBe(['a', 'b', 'c']);
```

### tail

[](#tail)

Skip all but `n` items from Iterator.

```
$actual = tail(gen(5), 3, false);
expect(iterator_to_array($actual))->toBe(['c', 'd', 'e']);
```

### head

[](#head)

Iterator over `n` first items.

```
$actual = head(gen(10), 3);
expect(iterator_to_array($actual))->toBe(['a', 'b', 'c']);
```

### skip

[](#skip)

Skip `n` items and iterate over rest.

```
$actual = skip(gen(10), 4);
expect(iterator_to_array($actual))->toBe(['e', 'f', 'g', 'h', 'i', 'j']);
```

### tee

[](#tee)

Split Iterator to two independent Iterators (with internal buffering).

```
list($left, $right) = tee(gen(10));

expect(iterator_to_array(head($left, 3)))->toBe(['a', 'b', 'c']);
expect(iterator_to_array(head($right, 5)))->toBe(['a', 'b', 'c', 'd', 'e']);

expect(iterator_to_array(head($left, 5)))->toBe(['d', 'e', 'f', 'g', 'h']);
expect(iterator_to_array(head($right, 2)))->toBe(['f', 'g']);

expect(iterator_to_array(head($left, 2)))->toBe(['i', 'j']);
expect(iterator_to_array(head($right, 3)))->toBe(['h', 'i', 'j']);
```

### chain

[](#chain)

Iterate over first, then second, third...

```
$actual = chain(gen(5), gen(3));
expect(iterator_to_array($actual))->toBe(['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c']);
```

### filter

[](#filter)

Iterate ovel all but yield only filtered items.

```
$actual = filter(gen(10), function ($item, $key) {
    return $key % 2 == 1;
});
expect(iterator_to_array($actual))->toBe(['b', 'd', 'f', 'h', 'j']);
```

### map

[](#map)

Return new Iterator with mapped values

```
$actual = map(gen(3), function ($item, $key) {
    return "item {$key}: {$item}";
});

expect(iterator_to_array($actual))->toBe(['item 0: a', 'item 1: b', 'item 2: c']);
```

### chunk

[](#chunk)

Return iterator of chunk iterators.

```
$actual = \iterator_to_array(map(chunk(gen(10), 3), '\\iterator_to_array'));
expect($actual)->toBe([
    ['a', 'b', 'c'],
    ['d', 'e', 'f'],
    ['g', 'h', 'i'],
    ['j']
]);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

3112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e88ca2d7f73ceff94c308858b21961859448f73770f40d230788e9e947317297?d=identicon)[thesebas](/maintainers/thesebas)

---

Top Contributors

[![thesebas](https://avatars.githubusercontent.com/u/827416?v=4)](https://github.com/thesebas "thesebas (10 commits)")

### Embed Badge

![Health badge](/badges/thesebas-itertools/health.svg)

```
[![Health](https://phpackages.com/badges/thesebas-itertools/health.svg)](https://phpackages.com/packages/thesebas-itertools)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
