Files
Ratte/common/slices/slice.go
2024-09-12 06:04:32 +09:00

19 lines
327 B
Go

package slices
func Range[t any](sl []t, handle func(i int, v t) (_break bool)) {
for i := range sl {
b := handle(i, sl[i])
if b {
break
}
}
}
func RangeToNew[old, new any](sl []old, handle func(i int, v old) new) []new {
ns := make([]new, len(sl))
for i := range ns {
ns[i] = handle(i, sl[i])
}
return ns
}