package main
import (
"fmt"
)
func main() {
multiply := func(values []int, multiplier int) []int {
multipliedValues := make([]int, len(values))
for i, v := range values {
multipliedValues[i] = v * multiplier
}
return multipliedValues
}
add := func(values []int, additive int) []int {
addedValues := make([]int, len(values))
for i, v := range values {
addedValues[i] = v + additive
}
return addedValues
}
ints := []int{1, 2, 3, 4}
for _, v := range add(multiply(ints, 2), 1) {
fmt.Println(v)
}
fmt.Println("")
for _, v := range multiply(add(multiply(ints, 2), 1), 2) {
fmt.Println(v)
}
}
有疑问加站长微信联系(非本文作者)