feat: add mapping functions
This commit is contained in:
21
internal/author/mapper.go
Normal file
21
internal/author/mapper.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package author
|
||||
|
||||
import "tutorial.sqlc.dev/app/internal/author/gen"
|
||||
|
||||
func toAuthor(a gen.Author) Author {
|
||||
return Author{
|
||||
a.ID, a.Name, a.Bio.String,
|
||||
}
|
||||
}
|
||||
|
||||
func mapSlice[K any, V any](conv func(K) V) func([]K) []V {
|
||||
return func(inputs []K) []V {
|
||||
output := make([]V, len(inputs))
|
||||
for i, input := range inputs {
|
||||
output[i] = conv(input)
|
||||
}
|
||||
return output
|
||||
}
|
||||
}
|
||||
|
||||
var toAuthorSlice = mapSlice(toAuthor)
|
||||
Reference in New Issue
Block a user