MCPcopy Create free account
hub / github.com/sourcegraph/conc / MapErr

Method MapErr

iter/map.go:48–65  ·  view source on GitHub ↗

MapErr applies f to each element of the input, returning the mapped result and a combined error of all returned errors. Map uses up to the configured Mapper's maximum number of goroutines.

(input []T, f func(*T) (R, error))

Source from the content-addressed store, hash-verified

46//
47// Map uses up to the configured Mapper's maximum number of goroutines.
48func (m Mapper[T, R]) MapErr(input []T, f func(*T) (R, error)) ([]R, error) {
49 var (
50 res = make([]R, len(input))
51 errMux sync.Mutex
52 errs error
53 )
54 Iterator[T](m).ForEachIdx(input, func(i int, t *T) {
55 var err error
56 res[i], err = f(t)
57 if err != nil {
58 errMux.Lock()
59 // TODO: use stdlib errors once multierrors land in go 1.20
60 errs = multierror.Join(errs, err)
61 errMux.Unlock()
62 }
63 })
64 return res, errs
65}

Callers 1

MapErrFunction · 0.80

Calls 1

ForEachIdxMethod · 0.80

Tested by

no test coverage detected