mirror of
https://github.com/InazumaV/Ratte.git
synced 2026-02-04 04:30:09 +00:00
Initial commit
This commit is contained in:
18
common/slices/slice.go
Normal file
18
common/slices/slice.go
Normal file
@@ -0,0 +1,18 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user