← All recipes
Moderne licensed

Migrate golang.org/x/exp/slices to slices

Recipe IDorg.openrewrite.golang.migration.MigrateXExpSlicesToStdlibArtifactgithub.com/moderneinc/recipes-go

Repoint golang.org/x/exp/slices at the standard library slices, added in Go 1.21. Every x/exp function exists there under the same name and signature, so call sites are unchanged. A file is skipped when the module targets an older Go release, when it already imports slices, or when it passes a boolean comparator to SortFunc, SortStableFunc, IsSortedFunc, MinFunc or MaxFunc — the pre-2023 x/exp signature, which needs a hand conversion to a three-way cmp function.

Single recipeProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.golang.migration.MigrateXExpSlicesToStdlib

If the recipe isn’t available locally, install it with:

mod config recipes go install github.com/moderneinc/recipes-go