v0.0.64
This commit is contained in:
parent
412277b3e0
commit
b9c46947d2
@ -37,3 +37,21 @@ func IsSliceSorted[T any](arr []T, less func(v1, v2 T) bool) bool {
|
||||
return less(arr[i1], arr[i2])
|
||||
})
|
||||
}
|
||||
|
||||
func SortBy[TElem any, TSel OrderedConstraint](arr []TElem, selector func(v TElem) TSel) {
|
||||
sort.Slice(arr, func(i1, i2 int) bool {
|
||||
return selector(arr[i1]) < selector(arr[i2])
|
||||
})
|
||||
}
|
||||
|
||||
func SortByStable[TElem any, TSel OrderedConstraint](arr []TElem, selector func(v TElem) TSel) {
|
||||
sort.SliceStable(arr, func(i1, i2 int) bool {
|
||||
return selector(arr[i1]) < selector(arr[i2])
|
||||
})
|
||||
}
|
||||
|
||||
func IsSortedBy[TElem any, TSel OrderedConstraint](arr []TElem, selector func(v TElem) TSel) {
|
||||
sort.SliceStable(arr, func(i1, i2 int) bool {
|
||||
return selector(arr[i1]) < selector(arr[i2])
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user