File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,10 @@ type Set[T comparable] interface {
161161 // Iterator returns an Iterator object that you can
162162 // use to range over the set.
163163 Iterator () * Iterator [T ]
164+
165+ // MatchesFunc() returns whether at least one element in the set
166+ // matches the provided predicate function.
167+ MatchesFunc (func (T ) bool ) bool
164168
165169 // Remove removes a single element from the set.
166170 Remove (i T )
Original file line number Diff line number Diff line change @@ -62,6 +62,14 @@ func (t *threadSafeSet[T]) Append(v ...T) int {
6262 return ret
6363}
6464
65+ func (t * threadSafeSet [T ]) MatchesFunc (predicate func (T ) bool ) bool {
66+ t .RLock ()
67+ ret := t .uss .MatchesFunc (predicate )
68+ t .RUnlock ()
69+
70+ return ret
71+ }
72+
6573func (t * threadSafeSet [T ]) Contains (v ... T ) bool {
6674 t .RLock ()
6775 ret := t .uss .Contains (v ... )
Original file line number Diff line number Diff line change @@ -89,6 +89,15 @@ func (s *threadUnsafeSet[T]) Clone() Set[T] {
8989 return clonedSet
9090}
9191
92+ func (s * threadUnsafeSet [T ]) MatchesFunc (predicate func (T ) bool ) bool {
93+ for elem := range * s {
94+ if predicate (elem ) {
95+ return true
96+ }
97+ }
98+ return false
99+ }
100+
92101func (s * threadUnsafeSet [T ]) Contains (v ... T ) bool {
93102 for _ , val := range v {
94103 if _ , ok := (* s )[val ]; ! ok {
You can’t perform that action at this time.
0 commit comments