feature: added optional

This commit is contained in:
2024-06-25 12:35:10 +03:00
parent 33bc425e90
commit 7cad10126c
4 changed files with 106 additions and 0 deletions

View File

@@ -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]()
}