Menu

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

Go's slices Package: 11 Functions That Replace Half Your Helpers

DEV Community·Gabriel Anhaia·27 days ago
#UFTdj5qV
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 internal/util/slice.go in any Go service that was bootstrapped before 1.21. You'll find ContainsString , IndexOfInt , a hand-rolled removeAt , two versions of uniq , and a mergeSlices helper that someone copy-pasted from Stack Overflow in 2019. Most of that file can go. Go 1.21 shipped the slices package in August 2023, and 1.22 filled in the last gap with Concat . Eleven of those functions cover the work those helpers were doing. The migration is mechanical: import "slices" , delete the helper, replace the call. There's one catch worth knowing before you swap. Delete and Compact quietly changed behavior between 1.21 and 1.22 in a way that affects pointer-heavy slices.…

Continue reading — create a free account

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

Read More