🌟 Go 1.23 Extends For-Range Loops with New Range Types

Tom Smykowski
2 min read4 days ago

Go 1.23 introduces a progressive update for for-range loops, now supporting a wider array of range types. This enhancement simplifies handling complex range expressions, making your code cleaner and more versatile.

Go 1.23 was released like a month ago, but I was unable to cover that release earlier due to vacation season. But it’s not that bad, because I can do it for you now. There are various interesting features and fixes in this release.

This article was brought to you thanks to 18 thousand followers on Medium

But for me the most peculiar is the extended range clause in a for-range loop. It accepts now these types as range expressions.

func(func() bool)
func(func(K) bool)
func(func(K, V) bool)

Range-over function was made available in Go as far away as Go 1.18. You can read about it here.

If you like the article follow me and subscribe for more!

Here’s a nice example that shows the power of range over function:

// LongStrings returns a slice of just the values
// in m whose length is n or more.
func LongStrings(m map[int]string…

--

--

Tom Smykowski

Software Engineer & Tech Editor. Top 2% on StackOverflow, 3mil views on Quora. Won Shattered Pixel Dungeon.