underscore
GitHub Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Map

Map produces a new slice of values by mapping each value in the slice through a transform function.

package main

import (
 "fmt"
 u "github.com/rjNemo/underscore"
)

func main() {
 nums := []int{1, 2, 3}
 toSquare := func(n int) int {
  return n * n
 }
 fmt.Println(u.Map(nums, toSquare)) // {1, 4, 9}
}