Skip to content

Commit

Permalink
Add SomeBy function
Browse files Browse the repository at this point in the history
  • Loading branch information
utgwkk committed Nov 28, 2023
1 parent d3d87e0 commit ff45392
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions godash.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func EveryBy[T any](collection []T, predicate func(item T) bool) bool {
return lo.EveryBy(collection, predicate)
}

// SomeBy returns whether or not any of the values within the collection meet the predicate.
func SomeBy[T any](collection []T, predicate func(item T) bool) bool {
return lo.SomeBy(collection, predicate)
}

// NoneBy returns whether or not all the values within the collection do not meet the predicate.
func NoneBy[T any](collection []T, predicate func(item T) bool) bool {
return lo.NoneBy(collection, predicate)
Expand Down
16 changes: 16 additions & 0 deletions godash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ func ExampleEveryBy() {
// Output: true
}

func ExampleSomeBy() {
type User struct {
name string
age int
}
users := []User{
{"foo", 20},
{"bar", 25},
{"baz", 40},
}
fmt.Println(godash.SomeBy(users, func(u User) bool {
return u.age >= 30
}))
// Output: true
}

func ExampleNoneBy() {
type User struct {
name string
Expand Down

0 comments on commit ff45392

Please sign in to comment.