3 ms·
Coming Soon: Golang 1.22
- 38 3y agothis 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.