currently, we cannot sort Slice or StaticArray directly.
Could you expand a bit on your usecases?
@jhass when interacting with C API, a pointer is passed from C API which represents an array. I want to do something on this pointer without create a new array.
Creating a new array from a Slice or StaticArray just to sort is unnecessary, adding sort to the slice object sound good to me.
I think we could implement this, the algorithm in Array works on Pointer so it would be easy to move this code to Slice or maybe Pointer and use it in Array, Slice and StaticArray.
@asterite Definitely slice, constructing a slice from a pointer is "free" and it provides a far better interface for working on what is conceptually a slice
@straight-shoota @asterite I would like to work on this, should I add the following methods to Slice only?
def sort(&block : T, T -> Int32) : Slice(T)def sort! : Slice(T)def sort!(&block : T, T -> Int32) : Slice(T)def sort_by(&block : T -> UNDERSCORE) : Slice(T)def sort_by!(&block : T -> UNDERSCORE) : Slice(T)Yeah, that seems to be the course of action :+1:
While doing that, I'd also suggest to move the implementation methods (intro_sort etc.) to a separate file, for example src/sort.cr or src/slice/sort.cr to better separate this feature for better code readability.
Most helpful comment
I think we could implement this, the algorithm in Array works on
Pointerso it would be easy to move this code toSliceor maybePointerand use it inArray,SliceandStaticArray.