Package: reiter
Wrapper for Python iterators and iterables that implements a list-like random-access interface by caching retrieved items for later reuse.Installation and UsageThis library is available as apackage on PyPI:python-mpipinstallreiterThe library can be imported in the usual way:importreiterfromreiterimportreiterExamplesThis library makes it possible to wrap anyiteratororiterableobject within an interface that enables repeated iteration over – and random access by index of – the items contained within that object. Areiterinstance yields the same sequence of items as the wrapped iterator or iterable:>>>fromreiterimportreiter>>>xs=iter([1,2,3])>>>ys=reiter(xs)>>>list(ys)[1,2,3]Unlike iterators and some iterable objects (including those that are built-in and those that are user-defined), an instance of thereiterclassalwaysallows iteration over its items any number of times. More specifically, every invocation ofiter(explicit or implicit) returns an iterator that begins iteration from the first item found in the originally wrapped iterator or iterable:>>>list(iter(ys)),list(iter(ys))([1,2,3],[1,2,3])>>>list(ys),list(ys)([1,2,3],[1,2,3])Furthermore, it is also possible to access elements by their index:>>>xs=iter([1,2,3])>>>ys=reiter(xs)>>>ys[0],ys[1],ys[2](1,2,3)The built-in Pythonnextfunction is also supported, and any attempt to retrieve an item once the sequence of items is exhausted raises theStopIterationexception in the usual manner:>>>xs=reiter(iter([1,2,3]))>>>next(xs),next(xs),next(xs)(1,2,3)>>>next(xs)Traceback(mostrecentcalllast):...StopIterationHowever, all items yielded during iteration can be accessed by their index, and it is also possible to iterate over those items again:>>>xs[0],xs[1],xs[2](1,2,3)>>>[xforxinxs][1,2,3]Retrieval of yielded items using slice notation is also supported via the__getitem__method:>>>xs=reiter(iter([1,2,3]))>>>xs[0:2][1,2]Instances ofreitersupport additional inspection methods, as well. For example, thehasmethod returns a boolean value indicating whether a next item is available and thelengthmethod returns the length of the sequence of items emitted by the instance (once no more items can be emitted):>>>xs=reiter(iter([1,2,3]))>>>xs.has(),xs.has(),xs.has(),xs.has()(True,True,True,False)>>>xs.length()3DevelopmentAll installation and development dependencies are fully specified inpyproject.toml. Theproject.optional-dependenciesobject is used tospecify optional requirementsfor various development tasks. This makes it possible to specify additional options (such asdocs,lint, and so on) when performing installation usingpip:python-mpipinstall.[docs,lint]DocumentationThe documentation can be generated automatically from the source files usingSphinx:python-mpipinstall.[docs]cddocssphinx-apidoc-f-E--templatedir=_templates-o_source..&&makehtmlTesting and ConventionsAll unit tests are executed and their coverage is measured when usingpytest(see thepyproject.tomlfile for configuration details):python-mpipinstall.[test]python-mpytestAlternatively, all unit tests are included in the module itself and can be executed usingdoctest:pythonsrc/reiter/reiter.py-vStyle conventions are enforced usingPylint:python-mpipinstall.[lint]python-mpylintsrc/reiterContributionsIn order to contribute to the source code, open an issue or submit a pull request on theGitHub pagefor this library.VersioningThe version number format for this library and the changes to the library associated with version number increments conform withSemantic Versioning 2.0.0.PublishingThis library can be published as apackage on PyPIby a package maintainer. First, install the dependencies required for packaging and publishing:python-mpipinstall.[publish]Ensure that the correct version number appears inpyproject.toml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has anautomation rulethat activates and sets as the default all tagged versions. Create and push a tag for this version (replacing?.?.?with the version number):gittag?.?.?gitpushorigin?.?.?Remove any old build/distribution files. Then, package the source into a distribution archive:rm-rfbuilddistsrc/*.egg-infopython-mbuild--sdist--wheel.Finally, upload the package distribution archive toPyPI:python-mtwineuploaddist/*