1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 08:12:26 +08:00

feat: add Minus func for set

This commit is contained in:
dudaodong
2022-04-01 16:44:25 +08:00
parent 79867e8a63
commit f28b5b2f92
2 changed files with 24 additions and 0 deletions

View File

@@ -103,3 +103,16 @@ func (s Set[T]) Intersection(other Set[T]) Set[T] {
return set
}
// Minus creates an set of whose element in origin set but not in compared set
func (s Set[T]) Minus(comparedSet Set[T]) Set[T] {
set := NewSet[T]()
s.Iterate(func(value T) {
if !comparedSet.Contain(value) {
set.Add(value)
}
})
return set
}