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))
| 59 | // returning the first error that occurred invoking the map function, if there |
| 60 | // was one. |
| 61 | func 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. |
no outgoing calls
searching dependent graphs…