Created
April 27, 2021 02:23
-
-
Save thepabloaguilar/9762d5b1f62f73fff83b17dc2125ec16 to your computer and use it in GitHub Desktop.
Revisions
-
thepabloaguilar created this gist
Apr 27, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ package main import ( "fmt" "strconv" ) func Map[T1, T2 any](s []T1, f func(T1) T2) []T2 { newSlice := make([]T2, 0) for _, item := range s { newSlice = append(newSlice, f(item)) } return newSlice } func main() { s := []int {1, 2, 3, 4} newS := Map(s, strconv.Itoa) fmt.Printf("%T -> %s", newS, newS) // []string -> [1 2 3 4] }