initial commit

This commit is contained in:
2025-12-31 15:33:16 -05:00
commit 89f2114b06
51 changed files with 4779 additions and 0 deletions

36
backend/pkg/slices/map.go Normal file
View File

@@ -0,0 +1,36 @@
package slices
// Map consumes []T and a function that returns D
func Map[T, D any](srcItems []T, mapFunc func(T) D) []D {
dstItems := make([]D, len(srcItems))
for i, v := range srcItems {
dstItems[i] = mapFunc(v)
}
return dstItems
}
// First returns the first of a slice
func First[T any](s []T) (item T, found bool) {
if len(s) > 0 {
return s[0], true
}
return item, false
}
// Last returns the last of a slice
func Last[T any](s []T) (item T, found bool) {
if len(s) > 0 {
return s[len(s)-1], true
}
return item, false
}
// FindFirst finds the first matching item in s given fn
func FindFirst[T any](s []T, fn func(T) bool) (item T, found bool) {
for _, v := range s {
if fn(v) {
return v, true
}
}
return item, false
}