Range over function

Go 1.23 introduced “range over function types”, which lets you implement custom logic for ranging over values in a ‘for’ statement.

=> Announcement post [go.dev]

They're an interesting take on iterators (specifically “push” iterators) that are unlike most other languages. They work even in the presence of ‘return’, ‘break’, ‘continue’, ‘goto’, and ‘defer’ inside the loop body.

mcyoung has a good writeup of the code rewrite that's needed to make that work.

=> Go's Weird Little Iterators [mcyoung.xyz]

That includes a link to the behemoth of a comment from Russ Cox and David Chase in the rewrite implementation.

=> Package rangefunc [cs.opensource.google]

=> » Languages » Go

Proxy Information
Original URL
gemini://dcreager.net/languages/go/range-func.gmi
Status Code
Success (20)
Meta
text/gemini;lang=en
Capsule Response Time
558.190305 milliseconds
Gemini-to-HTML Time
0.53608 milliseconds

This content has been proxied by September (ba2dc).