Back to Lo

Core Minindexby

docs/data/core-minindexby.md

1.53.0292 B
Original Source

Searches the minimum value using a comparison function and returns the value and its index. Returns (zero value, -1) when empty.

go
type Point struct{ X int }
value, idx := lo.MinIndexBy([]Point{{1}, {5}, {3}}, func(a, b Point) bool {
    return a.X < b.X
})
// value == {1}, idx == 0