RFC: Use Go 1.23 iterators for locking+traversing stores. #2288
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RFC: this is a ~demo, only migrating one function out of several.
This replaces one kind of boilerplate with another, but overall seems a bit less repetitive. The primary benefit is that the code working within the locked stores can
return
directly, without boilerplate, and there is no need to manually declare afunc(…)
for the loop body.The
for store, err := range
syntax is a bit weird, admittedly, but maybe worth it.The primary downside is that this really doesn’t work for the exactly-one-closure-call helpers (
writeTo…Store
):for store, err := range writeToSingleStore
is very unintuitive, but maybe acceptable with good helper namesreturn
s, there is no need for the code afterwards toreturn
as well. So every caller would need to add an unreachable inventedreturn
there… and that seems a bit much for me.So, we would end up with two rather different helper patterns instead of ~one. I’m really unsure whether it is worth it. It might well make sense to leave the code as is, and to wait another 1/5/10 years for Go to gain type inference and a convenient closure syntax.