DEV Community

Cheikh Seck
Cheikh Seck

Posted on

Go 1.23’s Iter package

A post about writing a custom iterator that returns a map’s values in a constant order.

Maps are notoriously known for changing their iteration order during each range loop. “When iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same from one iteration to the next.” The solution proposed by the Go team was to define a separate data structure that explicitly specifies the order of iteration; this may be a slice or array with the keys in the desired order.

Image description

In this post, we’ll look at a recent approach to solving the iteration order problem; as well as understand how to define a really basic iterator with the iter package.

You can read the rest here:

https://cheikhhseck.medium.com/go-1-23s-iter-package-f6b44dfb9b7b?source=friends_link&sk=1cbef6905c4acaa7b816e661068f967a

Top comments (0)