github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/slice/stablesort/api.go (about) 1 // Package stablesort provides stable sorting in place slice elements 2 package stablesort 3 4 import ( 5 "golang.org/x/exp/constraints" 6 7 "github.com/m4gshm/gollections/convert/as" 8 "github.com/m4gshm/gollections/slice" 9 ) 10 11 // By sorts elements in ascending order, using the orderConverner function to retrieve a value of type Ordered. 12 func By[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverter func(T) O) TS { 13 return slice.StableSortAsc(elements, orderConverter) 14 } 15 16 // Asc sorts orderable elements ascending 17 func Asc[T constraints.Ordered, TS ~[]T](elements TS) TS { 18 return slice.StableSortAsc(elements, as.Is[T]) 19 } 20 21 // Desc sorts orderable elements descending 22 func Desc[T constraints.Ordered, TS ~[]T](elements TS) TS { 23 return slice.StableSortDesc(elements, as.Is[T]) 24 }