viralogic / py-enumerable

A Python module used for interacting with collections of objects using LINQ syntax
MIT License
188 stars 24 forks source link

Retain Enumerable ordering #73

Closed viralogic closed 1 year ago

viralogic commented 2 years ago

Current implementation of the Enumerable results in inconsistent results when calling methods such as first(). For example:

e = Enumerable((x for x in range(0, 5)))
e.first() # 0
e.first() # 1

As you can see, both the calls to first() should give 0.

This is because of how the repeatable iterator is implemented for the Enumerable does not keep track of the start of the iterator when it is exhausted/used. Thus, subsequent calls of any methods that require iterating over the Enumerable could start from a non-zero start position and possibly give different results for subsequent calls.