Files
kurious/pkg/slices/map.go
Aleksandr Trushkin 48f5d80f7a add more style
2024-01-05 23:03:15 +03:00

18 lines
267 B
Go

package slices
// Map slice from one type to another one.
func Map[S any, E any](s []S, f func(S) E) []E {
out := make([]E, len(s))
for i := range s {
out[i] = f(s[i])
}
return out
}
func ForEach[S any](s []S, f func(S)) {
for i := range s {
f(s[i])
}
}