-
-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Describe the project you are working on
Online multiplayer survival game.
Describe the problem or limitation you are having in your project
The already existing sort() is less convenient than it should be. I find that the majority of the time I want to sort a container I am already duplicating it and maybe half of the time I will be iterating on it, but sort() only operates in-place and having no return value feels incorrect. You can't do method chaining on it and in cases it breaks the natural flow of code. Some container methods, such as filter(), map(), and slice(), return a copy whereas sort() instead operates in-place which in my opinion makes things more confusing. To add to this we already have Dictionary.merge() and Dictionary.merged() which was either a mistake or shows that there is a place for convenience methods like this in the engine.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a sorted() method which returns a sorted copy. This is what I would be using the majority of the time due to convenience. sort() can remain for the case where you want better performance for in-place sorting.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
See godotengine/godot#112138 for an implementation. It implements sorted() for Dictionary, Array, and all of the packed arrays, and sorted_custom() to Array.
If this enhancement will not be used often, can it be worked around with a few lines of script?
I think this enhancement would be used often, but yes it could be worked around with a few lines. The point is to increase convenience by not having to write these few lines every time you want to sort.
Is there a reason why this should be core and not an add-on in the asset library?
This is about modifying a core Variant.