slices/each.go

12 lines
198 B
Go
Raw Normal View History

2022-09-06 01:58:19 +02:00
package slices
func Each[T any](slice []T, f func(T)) {
EachIndex(slice, func(_ int, v T) { f(v) })
}
func EachIndex[T any](slice []T, f func(int, T)) {
for i, v := range slice {
f(i, v)
}
}