36 lines
602 B
Go
36 lines
602 B
Go
package bunmodel
|
|
|
|
func sliceToDomain[T interface {
|
|
ToDomain() (V, error)
|
|
}, V any](s []T) ([]V, error) {
|
|
res := make([]V, 0, len(s))
|
|
|
|
for _, el := range s {
|
|
converted, err := el.ToDomain()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res = append(res, converted)
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func sliceToDomainWithRelations[T interface {
|
|
ToDomainWithRelations() (V, error)
|
|
}, V any](s []T) ([]V, error) {
|
|
res := make([]V, 0, len(s))
|
|
|
|
for _, el := range s {
|
|
converted, err := el.ToDomainWithRelations()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res = append(res, converted)
|
|
}
|
|
|
|
return res, nil
|
|
}
|