Post

妙用Go泛型之结构体批量转换

1
2
3
4
5
6
7
func Map[T any, R any](slice []T, fn func(T) R) []R {
    result := make([]R, len(slice))
    for i, v := range slice {
        result[i] = fn(v)
    }
    return result
}
This post is licensed under CC BY 4.0 by the author.