lumiluminousai / golang-fp-utility

This Go package is crafted to help developers embrace functional programming paradigms in Go. With a suite of utility functions, this package encourages immutable coding practices, helping you move away from traditional mutable loops like for loops. Together
GNU Lesser General Public License v3.0
0 stars 2 forks source link

need ParallelMap function, Applies the Map function in parallel, utilizing goroutines to process elements concurrently #40

Open lumiluminousai opened 2 months ago

lumiluminousai commented 2 months ago

func ParallelMap[T1 any, T2 any](source []T1, transform func(T1) T2) []T2

Description: Applies the Map function in parallel, utilizing goroutines to process elements concurrently. This is particularly useful when the transformation is CPU-bound and can benefit from concurrency.

Why: Increases the performance of large data transformations by leveraging Go’s concurrency model.

result := ParallelMap([]int{1, 2, 3}, func(n int) int { time.Sleep(1 time.Second) // Simulate a long-running task return n 2 })