Created
April 4, 2025 11:11
-
-
Save doismellburning/ff6eeed14e87626dea49b167030c4a5c to your computer and use it in GitHub Desktop.
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 characters
// Have I missed something? Why doesn't Go's stdlib have this? | |
// Surely it's one of the first things you add when you've just added generics support? | |
func Map[FromType, ToType any](slice []FromType, f func(FromType) ToType) []ToType { | |
var result = make([]ToType, len(slice)) | |
for i, v := range slice { | |
result[i] = f(v) | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment