Files
lo/docs/data/it-minby.md
T
2025-10-08 19:35:53 +02:00

828 B

name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures playUrl variantHelpers similarHelpers position
MinBy minby it/find.go#L242 it find
func MinBy[T any](collection iter.Seq[T], comparison func(a, b T) bool) T
https://go.dev/play/p/5CwPTPz-zb
it#find#minby
core#slice#minby
it#find#maxby
it#find#min
140

Searches minimum value using a custom comparison function. The comparison function should return true if the first argument is "less than" the second.

Examples:

type Person struct {
    Name string
    Age  int
}
seq := func(yield func(Person) bool) {
    _ = yield(Person{"Alice", 30})
    _ = yield(Person{"Bob", 25})
    _ = yield(Person{"Charlie", 35})
}
youngest := it.MinBy(seq, func(a, b Person) bool {
    return a.Age < b.Age
})
// youngest == Person{"Bob", 25}