lo
lo copied to clipboard
feat: add parallel.Find
Useful when you don't care about the order and need any matching element in collection ASAP.
For example, this snippet
func main() {
start := time.Now()
lo.Find([]string{"a", "b", "c", "d"}, func(letter string) bool {
time.Sleep(1 * time.Second)
return letter == "c"
})
fmt.Printf("finished Find in %s\n", time.Since(start).String())
}
finishes in ~3 seconds, while parallel one
func main() {
start := time.Now()
lop.Find([]string{"a", "b", "c", "d"}, func(letter string) bool {
time.Sleep(1 * time.Second)
return letter == "c"
})
fmt.Printf("finished Find in %s\n", time.Since(start).String())
}
in ~1 second.
Any news ?