Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add All, Any for reducing to bool #54

Closed
elliot-u410 opened this issue Mar 21, 2022 · 2 comments
Closed

Add All, Any for reducing to bool #54

elliot-u410 opened this issue Mar 21, 2022 · 2 comments

Comments

@elliot-u410
Copy link

elliot-u410 commented Mar 21, 2022

All[T any](collection []T, predicate func (T) bool) bool would return true if all the elements pass the predicate and short-circuit to false otherwise.

Any[T any](collection []T, predicate func (T) bool) bool would return false if none the elements pass the predicate and short-circuit to true otherwise.

These are common functions in Rust, Haskell, many other languages.

@samber
Copy link
Owner

samber commented Apr 11, 2022

Thanks for your contributions @muety and @CorentinClabaut .

We already have 2 similar functions: Every and Some. With following prototypes:

func Every[T comparable](collection []T, subset []T) bool

func Some[T comparable](collection []T, subset []T) bool

In this package, a lot of functions are getting a ....By() declination.

For a better developer XP, I wonder if we should bring closer your functions such as:

func Every[T comparable](collection []T, subset []T) bool
func EveryBy[T comparable](collection []T, predicate func(V) bool) bool

func Some[T comparable](collection []T, subset []T) bool
func SomeBy[T comparable](collection []T, predicate func(V) bool) bool

func None[T comparable](collection []T, subset []T) bool
func NoneBy[T comparable](collection []T, predicate func(V) bool) bool

WDYT?

@CorentinClabaut
Copy link
Contributor

Good point.
I have update my PR to implement these functions. #67

@samber samber closed this as completed Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants