Menu

1 / 2

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

DEV Community·Gabriel Anhaia·6 months ago
#UFTdj5qV
#go#programming#stdlib#software#slices
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.…

Continue reading — create a free account

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