A static analysis tool for Go that detects usage of functions from third-party libraries and
suggests replacements using standard library functions or built-in language features. It leverages
Go’s analysis package to provide automated
refactorings and improvement suggestions.
See below for all the replacements of packages, functions and types. They will only be replaced if
the Go version of the file supports the new package.
Expand the sections below to see the supported replacements for each package.
github.com/samber/lo
Chunk
Before:
result := lo.Chunk(slice, size)
After:
result := slices.Chunk(slice, size)
Drop
Before:
a := []int{0, 1, 2, 3, 4, 5}
b := lo.Drop(a, 2)
After:
a := []int{0, 1, 2, 3, 4, 5}
b := a[2:]
DropRight
Before:
a := []int{0, 1, 2, 3, 4, 5}
b := lo.DropRight(a, 2)
After:
a := []int{0, 1, 2, 3, 4, 5}
b := a[:len(a)-2]
Contains
Before:
if lo.Contains(slice, target) {
// do something
}
After:
if slices.Contains(slice, target) {
// do something
}
ContainsBy
Before:
if lo.ContainsBy(slice, func(item int) bool {
return item > 10
}) {
// do something
}
After:
if slices.ContainsFunc(slice, func(item int) bool {
return item > 10
}) {
// do something
}
IndexOf
Before:
idx := lo.IndexOf(slice, target)
After:
idx := slices.Index(slice, target)
Min
Before:
min := lo.Min(slice)
After:
min := slices.Min(slice)
MinBy
Before:
min := lo.MinBy(slice, func(a, b int) bool {
return a < b
})
After:
min := slices.MinFunc(slice, func(a, b int) int {
return cmp.Compare(a, b)
})
Max
Before:
max := lo.Max(slice)
After:
max := slices.Max(slice)
MaxBy
Before:
max := lo.MaxBy(slice, func(a, b int) bool {
return a > b
})
After:
max := slices.MaxFunc(slice, func(a, b int) int {
return cmp.Compare(a, b)
})
IsSorted
Before:
if lo.IsSorted(slice) {
// do something
}
After:
if slices.IsSorted(slice) {
// do something
}
IsSortedByKey
Before:
sorted := lo.IsSortedByKey(slice, func(a string) string {
return a
})
After:
sorted := slices.IsSortedFunc(slice, func(a, next string) int {
return cmp.Compare(a, next)
})
Flatten
Before:
flattened := lo.Flatten(sliceOfSlices)
After:
flattened := slices.Concat(sliceOfSlices...)
Keys
Before:
keys := lo.Keys(m)
After:
keys := maps.Keys(m)
Values
Before:
values := lo.Values(m)
After:
values := maps.Values(m)
CoalesceOrEmpty
Before:
result := lo.CoalesceOrEmpty(s1, s2, s3)
After:
result := cmp.Or(s1, s2, s3)
RuneLength
Before:
n := lo.RuneLength(s)
After:
n := utf8.RuneCountInString(s)