feat: reducer, but doesn`t work

This commit is contained in:
2025-12-25 00:30:15 -05:00
parent 2c3ce9baf7
commit d5999e8e1c
15 changed files with 228 additions and 150 deletions

45
pkg/set/set.go Normal file
View File

@@ -0,0 +1,45 @@
package set
type Set[T comparable] map[T]bool
func (this *Set[T]) Add(items ...T) {
for _, item := range items {
(*this)[item] = true
}
}
func (this Set[T]) Has(item T) bool {
return this[item] == true
}
func (this *Set[T]) Remove(items ...T) {
for _, item := range items {
delete(*this, item)
}
}
func (this *Set[T]) Union(o Set[T]) {
for item := range o {
this.Add(item)
}
}
func (this Set[T]) ToList() []T {
list := []T{}
for item := range this {
list = append(list, item)
}
return list
}
func New[T comparable](items ...T) Set[T] {
result := Set[T]{}
for _, item := range items {
result.Add(item)
}
return result
}