Back to Lo

It Minby

docs/data/it-minby.md

1.53.0482 B
Original Source

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

Examples:

go
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}