shad-go/lectures/08-generics/scale/fixed/scale.go

12 lines
185 B
Go
Raw Permalink Normal View History

2022-04-07 15:04:16 +00:00
package wrong
import "golang.org/x/exp/constraints"
func Scale[S ~[]E, E constraints.Integer](s S, c E) S {
r := make(S, len(s))
for i, v := range s {
r[i] = v * c
}
return r
}