1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-13 01:02:28 +08:00

feat: add NewSetFromSlice function for set

This commit is contained in:
dudaodong
2022-11-30 12:00:55 +08:00
parent acb5844b15
commit 37c7508ad0
2 changed files with 22 additions and 0 deletions

View File

@@ -10,6 +10,15 @@ func NewSet[T comparable](items ...T) Set[T] {
return set
}
// NewSetFromSlice create a set from slice
func NewSetFromSlice[T comparable](items []T) Set[T] {
set := make(Set[T])
for _, item := range items {
set.Add(item)
}
return set
}
// Add items to set
func (s Set[T]) Add(items ...T) {
for _, v := range items {