Skip to content

Instantly share code, notes, and snippets.

@doismellburning
Created April 4, 2025 11:11
Show Gist options
  • Save doismellburning/ff6eeed14e87626dea49b167030c4a5c to your computer and use it in GitHub Desktop.
Save doismellburning/ff6eeed14e87626dea49b167030c4a5c to your computer and use it in GitHub Desktop.
// 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