Closed lasiar closed 2 weeks ago
I propose the following:
func Transform[S ~[]E, E any, T any](sl S, f func(E) T) []T { out := make([]T, len(sl)) for i, t := range sl { out[i] = f(t) } return out }
Something similar to the method from JS: map.
Using this code, you:
type user struct { id int64 } users := make([]user, 0) ... sendByIDs(slices.Transform(users, func(u user) int64 { return u.id }))
I believe that the name "map" could be confusing and may be associated with the type.
Duplicate of #58881
Proposal Details
Proposal Details
I propose the following:
Something similar to the method from JS: map.
Using this code, you:
Sample code:
Naming
I believe that the name "map" could be confusing and may be associated with the type.