feat: base implementation
This commit is contained in:
23
util/slices.go
Normal file
23
util/slices.go
Normal file
@ -0,0 +1,23 @@
|
||||
package util
|
||||
|
||||
func Transform[Tin any, Tout any](s []Tin, transformFn func(i *Tin) Tout) (out []Tout) {
|
||||
out = make([]Tout, 0)
|
||||
|
||||
for _, item := range s {
|
||||
out = append(out, transformFn(&item))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func Select[T any](s []T, selectFn func(i *T) bool) (out []T) {
|
||||
out = make([]T, 0)
|
||||
|
||||
for _, item := range s {
|
||||
if selectFn(&item) {
|
||||
out = append(out, item)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user