mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.2 KiB
1.2 KiB
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MinIndexBy | minindexby | it/find.go#L258 | it | find |
|
https://go.dev/play/p/6DxQUQ0-zc |
|
|
470 |
Searches the minimum value of a collection using a comparison function and returns both the value and its index.
If several values are equal to the smallest value, returns the first such value. Returns (zero value, -1) when the collection is empty. Will iterate through the entire sequence.
Examples:
// Find the minimum string by length and its index
words := it.Slice([]string{"apple", "hi", "banana", "ok"})
value, index := it.MinIndexBy(words, func(a, b string) bool {
return len(a) < len(b)
})
// value: "hi", index: 1
// Find the minimum person by age and its index
people := it.Slice([]Person{
{Name: "Alice", Age: 30},
{Name: "Bob", Age: 25},
{Name: "Charlie", Age: 35},
})
value, index := it.MinIndexBy(people, func(a, b Person) bool {
return a.Age < b.Age
})
// value: {Name: "Bob", Age: 25}, index: 1