lo icon indicating copy to clipboard operation
lo copied to clipboard

feat: add parallel.Find

Open shekhirin opened this issue 2 years ago • 1 comments

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.

shekhirin avatar Jun 07 '22 13:06 shekhirin

Any news ?

FournyP avatar Jul 26 '23 20:07 FournyP