MCPcopy Index your code
hub / github.com/riverqueue/river / MapError

Function MapError

rivershared/util/sliceutil/slice_util.go:61–73  ·  view source on GitHub ↗

MapError manipulates a slice and transforms it to a slice of another type, returning the first error that occurred invoking the map function, if there was one.

(collection []T, mapFunc func(T) (R, error))

Source from the content-addressed store, hash-verified

59// returning the first error that occurred invoking the map function, if there
60// was one.
61func MapError[T any, R any](collection []T, mapFunc func(T) (R, error)) ([]R, error) {
62 result := make([]R, len(collection))
63
64 for i, item := range collection {
65 var err error
66 result[i], err = mapFunc(item)
67 if err != nil {
68 return nil, err
69 }
70 }
71
72 return result, nil
73}
74
75// Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept.
76// The order of result values is determined by the order they occur in the array.

Callers 15

JobDeleteManyMethod · 0.92
JobGetAvailableMethod · 0.92
JobGetByIDManyMethod · 0.92
JobGetByKindManyMethod · 0.92
JobGetStuckMethod · 0.92
JobInsertFastManyMethod · 0.92
JobInsertFullManyMethod · 0.92
JobListMethod · 0.92
JobScheduleMethod · 0.92
JobDeleteManyMethod · 0.92
JobGetAvailableMethod · 0.92

Calls

no outgoing calls

Tested by 1

TestMapErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…