MCPcopy
hub / github.com/AlistGo/alist / SliceConvert

Function SliceConvert

pkg/utils/slice.go:47–57  ·  view source on GitHub ↗

SliceConvert convert slice to another type slice

(srcS []S, convert func(src S) (D, error))

Source from the content-addressed store, hash-verified

45
46// SliceConvert convert slice to another type slice
47func SliceConvert[S any, D any](srcS []S, convert func(src S) (D, error)) ([]D, error) {
48 res := make([]D, 0, len(srcS))
49 for i := range srcS {
50 dst, err := convert(srcS[i])
51 if err != nil {
52 return nil, err
53 }
54 res = append(res, dst)
55 }
56 return res, nil
57}
58
59func MustSliceConvert[S any, D any](srcS []S, convert func(src S) D) []D {
60 res := make([]D, 0, len(srcS))

Callers 15

ListMethod · 0.92
listMethod · 0.92
ListMethod · 0.92
ListMethod · 0.92
ListMethod · 0.92
ListMethod · 0.92
ListMethod · 0.92
ListMethod · 0.92
ListMethod · 0.92
ListMethod · 0.92
ListMethod · 0.92
ListMethod · 0.92

Calls 1

convertFunction · 0.85

Tested by

no test coverage detected