lo icon indicating copy to clipboard operation
lo copied to clipboard

ContainsBy for map

Open davidkarlsen opened this issue 1 year ago • 2 comments

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

davidkarlsen avatar Nov 12 '23 21:11 davidkarlsen

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.

steve-hb avatar Nov 30 '23 14:11 steve-hb

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

davidkarlsen avatar Nov 30 '23 20:11 davidkarlsen