feat: add EachWithBreak for set

This commit is contained in:
dudaodong committed 2023-03-20 10:49:14 +08:00
1 parent 0b80074bb7
commit 70d0adde42
4 files changed
+97

No files matched your search

+10
View File
@@ -171,3 +171,13 @@ func (s Set[T]) Minus(comparedSet Set[T]) Set[T] {
return set
}
// EachWithBreak iterates over elements of a set and invokes function for each element,
// when iteratee return false, will break the for each loop.
func (s Set[T]) EachWithBreak(iteratee func(item T) bool) {
for v := range s {
if !iteratee(v) {
break
}
}
}