Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

The maps Stdlib in Go 1.21+: 8 Functions That Replace Half Your Map Helpers

DEV Community·Gabriel Anhaia·25 days ago
#DbH9IB7c
#go#stdlib#generics#backend#maps#keys
Reading 0:00
15s threshold

Book: The Complete Guide to Go Programming Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub Open the same internal/util/ folder you cleaned out when the slices package landed. The map version of that folder is still there: MapKeys[string, int] , mergeMaps , a cloneMap someone wrote because they got bitten by reference semantics once, and a mapsEqual that does the obvious thing in a slightly different way each time it appears. Most of that file can go too. The maps package shipped in Go 1.21 alongside slices , and Go 1.23 reshaped two of its most-used functions into iterators. Eight functions cover what your helpers were doing. The migration is the same shape as the slices one: import "maps" , delete the helper, replace the call. One trap catches everyone the first time. maps.Keys does not return []K anymore.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More