Goworkinggo1.21

The slices and maps packages

Generic helpers that replace hand-rolled loops.

Go 1.21 added slices and maps — type-safe Sort, Contains, Index, Max/Min, Reverse, and maps.Keys, so common collection chores stop being for-loops.

slices.Sort sorts in place

Gointro
0ms
[1 2 3 5 8 9][apple fig pear]
Reference · output compiled offline, not runnable in-browser

One generic slices.Sort call sorts both the []int and the []string in place — ascending numeric order for the ints, lexicographic for the strings — with no comparator and no per-type code.