feature: added optional
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"git.tswf.io/incredible-go/incredible-go-core/pkg/container/optional"
|
||||
)
|
||||
|
||||
func (self *ArrayList[T]) Add(element T) {
|
||||
@@ -190,3 +192,19 @@ func (self *ArrayList[T]) ToSlice() []T {
|
||||
result := slices.Clone(self.content)[:self.size]
|
||||
return result
|
||||
}
|
||||
|
||||
func (self *ArrayList[T]) Find(filter func(T) bool) *optional.Optional[T] {
|
||||
for index, value := range self.content {
|
||||
if index >= self.size {
|
||||
break
|
||||
}
|
||||
|
||||
passed := filter(value)
|
||||
|
||||
if passed {
|
||||
return optional.OfAny(value)
|
||||
}
|
||||
}
|
||||
|
||||
return optional.Empty[T]()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user