utilities icon indicating copy to clipboard operation
utilities copied to clipboard

Allow backwards enumeration of DeletableObjectList

Open paulcscharf opened this issue 9 years ago • 3 comments
trafficstars

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 avatar May 24 '16 07:05 paulcscharf

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

paulcscharf avatar Jul 21 '18 22:07 paulcscharf

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]

tomrijnbeek avatar Jul 21 '18 22:07 tomrijnbeek

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

paulcscharf avatar Jul 21 '18 22:07 paulcscharf