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

ContainsBy for map #393

Open
davidkarlsen opened this issue Nov 12, 2023 · 2 comments
Open

ContainsBy for map #393

davidkarlsen opened this issue Nov 12, 2023 · 2 comments

Comments

@davidkarlsen
Copy link

ContainsBy would simply be syntactic sugar for:

	filtered := lo.PickBy(m.Annotations, func(key, value string) bool {
		return key == "somekey" && value == "somevalue"
	})
	return len(filtered) > 0
@steve-hb
Copy link

But this way the code would continue iterating even when the condition was already true for one combination, wouldn't it?
We should consider changing either PickBy for offer a limit (maybe as an internal function?) or implement a new one similar to the old one but only finding the first entry and stop searching.

@davidkarlsen
Copy link
Author

But this way the code would continue iterating even when the condition was already true for one combination, wouldn't it? We should consider changing either PickBy for offer a limit (maybe as an internal function?) or implement a new one similar to the old one but only finding the first entry and stop searching.

True - my implementation is not efficient. a findFirst (which is a special case of findBy(expression, limit), where limit == 1) could be the underlying for the containsBy

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

2 participants