Back to Lo

Core Earliestby

docs/data/core-earliestby.md

1.53.0330 B
Original Source

Searches a collection for the element with the minimum time extracted by the predicate. Returns zero value when the collection is empty.

go
type Event struct{ At time.Time }
events := []Event{{At: time.Now().Add(2 * time.Hour)}, {At: time.Now()}}
first := lo.EarliestBy(events, func(e Event) time.Time {
    return e.At
})