You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In go 1.23 they accepted functional iterators. We haven't used for loop statement because it wasn't clear what final interface would look like.
One can find all functional iterators by searching usages of iter.Seq or iter.Seq2 types.
Example:
eventsIt(func(res *spec.EventsResponse) bool {
switch v := res.EventMessage.(type) {
case *spec.EventsResponse_Event:
events = append(events, v.Event)
return true
case *spec.EventsResponse_Fin:
return false
default:
s.log.Warnw("Unexpected EventMessage from getEvents", "v", v)
return false
}
})
to be:
loop:
for res := range eventsIt {
switch v := res.EventMessage.(type) {
case *spec.EventsResponse_Event:
events = append(events, v.Event)
case *spec.EventsResponse_Fin:
break loop // mind the loop label, because just break key word doesn't affect iteration
default:
s.log.Warnw("Unexpected EventMessage from getEvents", "v", v)
break loop
}
})
or
for res := range eventsIt {
switch v := res.EventMessage.(type) {
case *spec.EventsResponse_Event:
events = append(events, v.Event)
continue // as far as I remember continue works fine inside select
case *spec.EventsResponse_Fin:
// will break in the end
default:
s.log.Warnw("Unexpected EventMessage from getEvents", "v", v)
}
// comment why
break
})
P.S. First you need to add GOEXPERIMENT=rangefunc env var. I suggest to put it on top of Makefile
The text was updated successfully, but these errors were encountered:
In go 1.23 they accepted functional iterators. We haven't used for loop statement because it wasn't clear what final interface would look like.
One can find all functional iterators by searching usages of
iter.Seq
oriter.Seq2
types.Example:
to be:
or
P.S. First you need to add
GOEXPERIMENT=rangefunc
env var. I suggest to put it on top of MakefileThe text was updated successfully, but these errors were encountered: