initial commit

This commit is contained in:
m.zare
2026-04-10 18:25:21 +03:30
commit 77ca6c34a3
263 changed files with 34470 additions and 0 deletions

39
pkg/array/any.go Normal file
View File

@@ -0,0 +1,39 @@
package array
func All[T any](arr []T, predicate func(val T) bool) bool {
for i := 0; i < len(arr); i++ {
if !predicate(arr[i]) {
return false
}
}
return true
}
// Any returns true if any element in the array satisfies the predicate; otherwise, it returns false.
func Any[TIn any](arr []TIn, predicate func(val TIn) bool) bool {
for i := 0; i < len(arr); i++ {
if predicate(arr[i]) {
return true
}
}
return false
}
func AnyError[TIn any](arr []TIn, predicate func(val TIn) error) error {
for i := 0; i < len(arr); i++ {
if err := predicate(arr[i]); err != nil {
return err
}
}
return nil
}
// Contains checks if a slice contains a specific element.
func Contains[T comparable](slice []T, element T) bool {
for i := 0; i < len(slice); i++ {
if slice[i] == element {
return true
}
}
return false
}