Closed krancour closed 1 month ago
I can take a look and work on this. Can you provide additional details?
Thanks for your interest @ankitsridhar16!
Can you provide additional details?
A lot of (if not, all) things that make use of sort
functions[1], should be rewritten so they use their slices
counterparts.
hey @hiddeco, i've tried implementing the solution for it. I'm getting stucked at how are we going to use the slices
package in order to sort based on a function, like here?
We can use the slices.SortFunc()
for this, however, the internal implementation of SortFunc
returns an int rather than bool value. Any suggestions here? After some more research, I think this is one of the way how we can implement this but would like to know your feedback on this:
slices.SortFunc(secretsList.Items, func(a, b corev1.Secret) int {
return cmp.Compare(a.Name, b.Name)
})
However, this does not work for sorting this piece of code.
As slices.SortFunc
documents:
cmp(a, b) should return a negative number when a < b, a positive number when a > b and zero when a == b.
This means you can use the Compare
method on time.Time
:
If t is before u, it returns -1; if t is after u, it returns +1; if they're the same, it returns 0.
Gotcha! Please assign this issue to me, I'll fix it.
Since Go 1.21, the
slices
package contains the preferred sorting implementations. Per Go documentations, they are both more ergonomic and more performant.This issue calls for remediating existing
sort.X()
function calls by replacing them with theirslices.X()
equivalent.