github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/slice/sort/api.go (about) 1 // Package sort provides sorting in place slice elements 2 package sort 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.SortAsc(elements, orderConverter) 14 } 15 16 // DescBy sorts elements in descending order, using the orderConverner function to retrieve a value of type Ordered. 17 func DescBy[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverter func(T) O) TS { 18 return slice.SortDesc(elements, orderConverter) 19 } 20 21 // Asc sorts orderable elements ascending 22 func Asc[T constraints.Ordered, TS ~[]T](elements TS) TS { 23 return slice.SortAsc(elements, as.Is[T]) 24 } 25 26 // Desc sorts orderable elements descending 27 func Desc[T constraints.Ordered, TS ~[]T](elements TS) TS { 28 return slice.SortDesc(elements, as.Is[T]) 29 }