Files
proton-bridge/internal/user/types.go
2022-11-16 12:26:09 +01:00

22 lines
359 B
Go

package user
import (
"fmt"
"reflect"
)
func mapTo[From, To any](from []From) []To {
to := make([]To, 0, len(from))
for _, from := range from {
val, ok := reflect.ValueOf(from).Convert(reflect.TypeOf(to).Elem()).Interface().(To)
if !ok {
panic(fmt.Sprintf("cannot convert %T to %T", from, *new(To)))
}
to = append(to, val)
}
return to
}