mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
e7386d9246
* Fix linting * Use is.ElementsMatch This will ignore the ordering of the final intersection. Especially important when checking old versions of go that do not guarantee an order when iterating through maps. * lint: fix inconsistent callback function parameter names * lint: rename "iteratee" to "transform" for *Map helpers * lint: rename "project" parameters to "transform" * lint: rename "cb" parameters to "callback" * lint: rename "iteratee" to "callback" for ForEach helpers --------- Co-authored-by: Franky W. <frankywahl@users.noreply.github.com> Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
1.1 KiB
1.1 KiB
name, slug, sourceRef, category, subCategory, playUrl, similarHelpers, position, signatures, variantHelpers
| name | slug | sourceRef | category | subCategory | playUrl | similarHelpers | position | signatures | variantHelpers | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Map | map | parallel/slice.go#L8 | parallel | slice | https://go.dev/play/p/sCJaB3quRMC |
|
0 |
|
|
Manipulates a slice and transforms it into a slice of another type. The transform is called in parallel and results are written back in the original order.
import (
"strconv"
lop "github.com/samber/lo/parallel"
)
out := lop.Map([]int64{1, 2, 3, 4}, func(x int64, i int) string {
return strconv.FormatInt(x, 10)
})
// []string{"1", "2", "3", "4"}
Parallel execution is useful when the predicate is slow or I/O-bound:
import (
"net/http"
"io"
lop "github.com/samber/lo/parallel"
)
urls := []string{"https://example.com/a", "https://example.com/b"}
pages := lop.Map(urls, func(u string, _ int) string {
resp, _ := http.Get(u)
defer resp.Body.Close()
b, _ := io.ReadAll(resp.Body)
return string(b)
})
// pages keeps the same order as urls