more helper functions

This commit is contained in:
Timon Ringwald
2022-09-06 01:58:19 +02:00
parent 4f3cf3f537
commit cdb1cf3e03
6 changed files with 87 additions and 18 deletions

11
each.go Normal file
View File

@ -0,0 +1,11 @@
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)
}
}