Source

go-play / map.go

package main

import "fmt"

func Map(f func(int) int, items []int) []int {
	results := make([]int, len(items))

	for index, item := range items {
		results[index] = f(item)
	}

	return results
}

func double(i int) int {
	return 2 * i
}

func main() {
	fmt.Println(Map(double, []int{1, 2, 3, 4}))
}