lo
lo copied to clipboard
ContainsBy for map
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
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.
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