CustomSortArray() + CustomSortList()
Posted: Fri Aug 25, 2023 11:05 am
Hello
I thought it would be awesome if we could sort Lists and Arrays using a callback, a bit like there's the CustomFilterCallback for 2D Drawing. For Lists,Arrays, StructuredLists and StructuredArrays.
I didn't know about CompareStructure() but I suppose it will go from first element to last element, and not let's say only check element #3 and then #2. With a custom sort callback you could change the sort order how you like.
CustomSortArray( Array(), @Procedure(), *userdata)
CustomSortList( List(), @Procedure(), *userdata)
Prototype.i CompareItem(*Left, *Right, *userdata) ; returns -1 of *left comes first, 1 if *right comes first, 0 if both are equal
I'd suggest that the elements always get treated like structures, so that when you have a string List or Array, both parameters are of the type .STRING instead of .s, .QUAD instead of .q etc. so the prototype always fits.
This is not an urgent feature request, there are also multiple user libraries that would allow it, I wrote own things to do similar things - but I always have to use help arrays and a bit of detours to get to where I want, and it could be faster and prettier. Just an idea.
I thought it would be awesome if we could sort Lists and Arrays using a callback, a bit like there's the CustomFilterCallback for 2D Drawing. For Lists,Arrays, StructuredLists and StructuredArrays.
I didn't know about CompareStructure() but I suppose it will go from first element to last element, and not let's say only check element #3 and then #2. With a custom sort callback you could change the sort order how you like.
CustomSortArray( Array(), @Procedure(), *userdata)
CustomSortList( List(), @Procedure(), *userdata)
Prototype.i CompareItem(*Left, *Right, *userdata) ; returns -1 of *left comes first, 1 if *right comes first, 0 if both are equal
I'd suggest that the elements always get treated like structures, so that when you have a string List or Array, both parameters are of the type .STRING instead of .s, .QUAD instead of .q etc. so the prototype always fits.
This is not an urgent feature request, there are also multiple user libraries that would allow it, I wrote own things to do similar things - but I always have to use help arrays and a bit of detours to get to where I want, and it could be faster and prettier. Just an idea.