Back to Lo

Core Uniqby

docs/data/core-uniqby.md

1.53.0239 B
Original Source

Returns a duplicate-free version of a slice based on a computed key. Keeps only the first element for each unique key.

go
lo.UniqBy(
    []int{0, 1, 2, 3, 4, 5},
    func(i int) int {
        return i % 3
    },
)
// []int{0, 1, 2}