diff --git a/langext/array.go b/langext/array.go index 60e9fba..430ef45 100644 --- a/langext/array.go +++ b/langext/array.go @@ -142,6 +142,27 @@ func ArrAnyErr(arr interface{}, fn func(int) (bool, error)) (bool, error) { return false, nil } +func ArrFirst[T comparable](arr []T, comp func(v T) bool) (T, bool) { + for _, v := range arr { + if comp(v) { + return v, true + } + } + return *new(T), false +} + +func ArrLast[T comparable](arr []T, comp func(v T) bool) (T, bool) { + found := false + result := *new(T) + for _, v := range arr { + if comp(v) { + found = true + result = v + } + } + return result, found +} + func AddToSet[T comparable](set []T, add T) []T { for _, v := range set { if v == add {