2017 © Pedro Peláez
 

library rewindable-generator

Provides a simple adapter to make generators rewindable

image

jeroen/rewindable-generator

Provides a simple adapter to make generators rewindable

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 73 % Grown

The README.md

Rewindable Generator

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Download count, (*1)

Provides a simple adapter to make generators rewindable. Please beware that you can do the same by using PHPs native CachingIterator., (*2)

Unfortunately, you cannot do this:, (*3)

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

Or this:, (*4)

$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., (*5)

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

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:, (*6)

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

Running the tests

For tests only, (*7)

composer test

For style checks only, (*8)

composer cs

For a full CI run, (*9)

composer ci

Release notes

Version 1.2.0 (2017-05-16)

  • Dropped PHP 5.x support

Version 1.1.1 (2015-11-08)

Version 1.1.0 (2015-11-08)

  • Added onRewind function and second constructor parameter to RewindableGenerator

Version 1.0.0 (2015-11-08)

The Versions

26/07 2018

dev-master

9999999-dev https://github.com/JeroenDeDauw/RewindableGenerator

Provides a simple adapter to make generators rewindable

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

  • php >=7.0

 

The Development Requires

generator iterator adapter rewind rewindable

16/05 2017

1.2.0

1.2.0.0 https://github.com/JeroenDeDauw/RewindableGenerator

Provides a simple adapter to make generators rewindable

  Sources   Download

GPL-2.0+

The Requires

  • php >=7.0

 

The Development Requires

generator iterator adapter rewind rewindable

08/11 2015

1.1.1

1.1.1.0 https://github.com/JeroenDeDauw/RewindableGenerator

Provides a simple adapter to make generators rewindable

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.0

 

The Development Requires

generator iterator adapter rewind rewindable

08/11 2015

1.1.0

1.1.0.0 https://github.com/JeroenDeDauw/RewindableGenerator

Provides a simple adapter to make generators rewindable

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.0

 

The Development Requires

generator iterator adapter rewind rewindable

08/11 2015

1.0.0

1.0.0.0 https://github.com/JeroenDeDauw/RewindableGenerator

Provides a simple adapter to make generators rewindable

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.0

 

The Development Requires

generator iterator adapter rewind rewindable