PHPackages                             jeroen/rewindable-generator - 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. jeroen/rewindable-generator

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

jeroen/rewindable-generator
===========================

Provides a simple adapter to make generators rewindable

1.2.0(9y ago)1655.9k↑61.1%12GPL-2.0+PHPPHP &gt;=7.0

Since Nov 8Pushed 7y ago3 watchersCompare

[ Source](https://github.com/JeroenDeDauw/RewindableGenerator)[ Packagist](https://packagist.org/packages/jeroen/rewindable-generator)[ Docs](https://github.com/JeroenDeDauw/RewindableGenerator)[ RSS](/packages/jeroen-rewindable-generator/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (5)Used By (2)

Rewindable Generator
====================

[](#rewindable-generator)

[![Build Status](https://camo.githubusercontent.com/249222fcbc17a7c8e56862ca3b8c47f28e36748b6bcdd6ed77767337103a51ce/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f4a65726f656e4465446175772f526577696e6461626c6547656e657261746f722e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/JeroenDeDauw/RewindableGenerator)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4cc2d9720aec4112620d68231262ab38fe626df06aaf43525f9cb1d89dd3d33c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4a65726f656e4465446175772f526577696e6461626c6547656e657261746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/JeroenDeDauw/RewindableGenerator/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/94ce94c72d77b64420507be319a8779928259fad38ac1bfdef882fef0fb09b5b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4a65726f656e4465446175772f526577696e6461626c6547656e657261746f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/JeroenDeDauw/RewindableGenerator/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/ec455d2d6e0b8b8c79c7d552c31150c97b78d46ec3f7158212974918509b0ab0/68747470733a2f2f706f7365722e707567782e6f72672f6a65726f656e2f726577696e6461626c652d67656e657261746f722f76657273696f6e2e706e67)](https://packagist.org/packages/jeroen/rewindable-generator)[![Download count](https://camo.githubusercontent.com/5ddc62b4130bcd34583f660ee8a2132c0ed369cee09431fd6abdc15e0902fa86/68747470733a2f2f706f7365722e707567782e6f72672f6a65726f656e2f726577696e6461626c652d67656e657261746f722f642f746f74616c2e706e67)](https://packagist.org/packages/jeroen/rewindable-generator)

Provides a simple adapter to make [generators](http://php.net/manual/en/language.generators.overview.php) rewindable. Please beware that you can do the same by using [PHPs native `CachingIterator`](https://secure.php.net/manual/en/class.cachingiterator.php).

Unfortunately, you cannot do this:

```
$generator = $myGeneratorFunction();
iterator_to_array($generator);
iterator_to_array($generator); // boom!
```

Or this:

```
$generator = $myGeneratorFunction();
$generator->next();
$generator->rewind(); // boom!
```

Both result in an `Exception`, as proven by the tests in `tests/GeneratorTest.php`. This library provides a simple class that takes a generator function (the function, not its return value) and adapts it to a rewindable `Iterator`.

```
$generator = new RewindableGenerator($myGeneratorFunction);
iterator_to_array($generator);
iterator_to_array($generator); // works as expected
$generator->rewind(); // works as expected
```

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

[](#installation)

To add this package as a local, per-project dependency to your project, simply add a dependency on `jeroen/rewindable-generator` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on Rewindable Generator 1.x:

```
{
    "require": {
        "jeroen/rewindable-generator": "~1.0"
    }
}
```

Running the tests
-----------------

[](#running-the-tests)

For tests only

```
composer test

```

For style checks only

```
composer cs

```

For a full CI run

```
composer ci

```

Release notes
-------------

[](#release-notes)

### Version 1.2.0 (2017-05-16)

[](#version-120-2017-05-16)

- Dropped PHP 5.x support

### Version 1.1.1 (2015-11-08)

[](#version-111-2015-11-08)

- Fixed HHVM compatibility. [Maybe...](https://github.com/facebook/hhvm/issues/1871)

### Version 1.1.0 (2015-11-08)

[](#version-110-2015-11-08)

- Added `onRewind` function and second constructor parameter to `RewindableGenerator`

### Version 1.0.0 (2015-11-08)

[](#version-100-2015-11-08)

- Initial release - [read blog post](http://www.bn2vs.com/blog/2015/11/08/rewindable-php-generators/)

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

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 ~185 days

Total

4

Last Release

3329d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.5.0

1.2.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

---

Top Contributors

[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (20 commits)")

---

Tags

generatoriteratoradapterrewindrewindable

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jeroen-rewindable-generator/health.svg)

```
[![Health](https://phpackages.com/badges/jeroen-rewindable-generator/health.svg)](https://phpackages.com/packages/jeroen-rewindable-generator)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k116.2M674](/packages/symfony-maker-bundle)[nikic/iter

Iteration primitives using generators

1.1k6.2M51](/packages/nikic-iter)[simplesoftwareio/simple-qrcode

Simple QrCode is a QR code generator made for Laravel.

2.9k29.5M105](/packages/simplesoftwareio-simple-qrcode)[loophp/collection

A (memory) friendly, easy, lazy and modular collection class.

743730.3k15](/packages/loophp-collection)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4531.2M5](/packages/athari-yalinqo)[ihor/nspl

Non-standard PHP library (NSPL) - functional primitives toolbox and more

375369.1k](/packages/ihor-nspl)

PHPackages © 2026

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