mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.1 KiB
1.1 KiB
name, slug, sourceRef, category, subCategory, variantHelpers, similarHelpers, position, signatures
| name | slug | sourceRef | category | subCategory | variantHelpers | similarHelpers | position | signatures | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| MinByErr | minbyerr | find.go#L349 | core | find |
|
|
161 |
|
Searches the minimum value of a collection using the given comparison function. Returns the first minimal value; zero value and nil error when empty.
If the comparison function returns an error, iteration stops and the error is returned.
type Point struct{ X int }
min, err := lo.MinByErr([]Point{{1}, {5}, {3}}, func(a, b Point) (bool, error) {
return a.X < b.X, nil
})
// {1}, <nil>
Example with error:
type Point struct{ X int }
min, err := lo.MinByErr([]Point{{1}, {5}, {3}}, func(a, b Point) (bool, error) {
if a.X == 5 {
return false, fmt.Errorf("cannot compare with 5")
}
return a.X < b.X, nil
})
// {0}, error("cannot compare with 5")