v0.0.100
This commit is contained in:
parent
2550691e2e
commit
c266d9204b
@ -217,6 +217,15 @@ func ArrFirst[T any](arr []T, comp func(v T) bool) (T, bool) {
|
||||
return *new(T), false
|
||||
}
|
||||
|
||||
func ArrFirstOrNil[T any](arr []T, comp func(v T) bool) *T {
|
||||
for _, v := range arr {
|
||||
if comp(v) {
|
||||
return Ptr(v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ArrLast[T any](arr []T, comp func(v T) bool) (T, bool) {
|
||||
found := false
|
||||
result := *new(T)
|
||||
@ -229,6 +238,22 @@ func ArrLast[T any](arr []T, comp func(v T) bool) (T, bool) {
|
||||
return result, found
|
||||
}
|
||||
|
||||
func ArrLastOrNil[T any](arr []T, comp func(v T) bool) *T {
|
||||
found := false
|
||||
result := *new(T)
|
||||
for _, v := range arr {
|
||||
if comp(v) {
|
||||
found = true
|
||||
result = v
|
||||
}
|
||||
}
|
||||
if found {
|
||||
return Ptr(result)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func ArrFirstIndex[T comparable](arr []T, needle T) int {
|
||||
for i, v := range arr {
|
||||
if v == needle {
|
||||
|
Loading…
Reference in New Issue
Block a user