45 ms·
this is completely pointless: func SortIterator[E cmp.Ordered](s []E) func(func(int, E) bool) { sortedSlice := make([]E, len(s)) copy(sortedS
by 38 3y ago
this is completely pointless:
func SortIterator[E cmp.Ordered](s []E) func(func(int, E) bool) {
sortedSlice := make([]E, len(s))
copy(sortedSlice, s)
slices.Sort(sortedSlice)
return func(yield func(int, E) bool) {
for i, v := range sortedSlice {
if !yield(i, v) {
return
}
}
}
}
the whole point of iterators is to be lazy. this is the opposite of that. its
sorting the entire slice before you have even iterated a single item.