Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow backwards enumeration of DeletableObjectList #62

Open
paulcscharf opened this issue May 24, 2016 · 3 comments
Open

Allow backwards enumeration of DeletableObjectList #62

paulcscharf opened this issue May 24, 2016 · 3 comments
Assignees

Comments

@paulcscharf
Copy link
Member

I have found the collection very useful in all sorts of places, most recently in a custom event-subscription system. For that I may want to enumerate the list in reverse, which can be done almost trivially by adding another Enumerator.

While the current enumerator also enumerates items that are added during enumeration, this new one would not, but that seems a minor issue, or maybe even desired behaviour.

I propose adding the following property:

IEnumerable<T> DeletableObjectList<T>.Reversed { get; }

The list could keep a no-data object internally which is returned with this property and implements GetEnumerator() correctly. While a bit of a shame in terms of memory, this will make sure there is no unnecessary pressure on the GC.

@paulcscharf
Copy link
Member Author

This still sounds potentially useful, but I do not remember the actual thing that made me create this issue in the first place. 🤔

@tomrijnbeek
Copy link
Member

Note that LINQ has a Reverse(), but my assumption is that this will first enumerate to list (or something similar), and then loop backwards, so that will work just fine already, it will just not skip if you delete an object before reaching it. In that case, Reverse() doesn't seem very useful. [/random]

@paulcscharf
Copy link
Member Author

Reverse() will enumerate and make a copy of the list, which is the last thing we want when making games.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants