I’m super excited to see range over functions - iterators. It’s one of the only things I miss from Java. It took me a few reads to understand how the work, but in typical Go style (once I got it) it was so much simpler than the equivalent in most other languages I’ve used. Looking forward to it being promoted out of experimental.
func Backward[E any](s []E) func(func(int, E) bool) {
return func(yield func(int, E) bool) {
for i := len(s)-1; i >= 0; i-- {
if !yield(i, s[i]) {
return
}
}
}
}
simpler than C#'s IEnumerable Backward(T[] s) {
for i := s.length-1; i >= 0; i-- {
yield return s[i];
}
}
I think that's quite hard to defend, honestly. Granted, Java doesn't have anything comparable, so I'm not sure what you're comparing this feature to.