set

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T comparable] map[T]struct{}

Set is a generic collection type that stores unique elements of type T.

It can be used as a replacement for map[T]struct{} with a cleaner API. The zero value (nil) is ready to use and represents an empty set.

The type implements:

  • Basic operations: Add, Remove, Contains, Len, ToSlice
  • Set operations: Append (union), Clone
  • JSON marshaling/unmarshaling
  • SQL driver.Valuer and sql.Scanner interfaces

All methods are safe to call on nil receiver and will not panic.

func NewSet

func NewSet[T comparable](items ...T) Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(items ...T)

func (*Set[T]) Append

func (s *Set[T]) Append(set Set[T])

func (*Set[T]) Clone

func (s *Set[T]) Clone() Set[T]

func (*Set[T]) Contains

func (s *Set[T]) Contains(item T) bool

func (*Set[T]) Len

func (s *Set[T]) Len() uint32

func (*Set[T]) MarshalJSON

func (s *Set[T]) MarshalJSON() ([]byte, error)

func (*Set[T]) Remove

func (s *Set[T]) Remove(item T)

func (*Set[T]) Reset

func (s *Set[T]) Reset()

func (*Set[T]) Scan

func (s *Set[T]) Scan(value interface{}) error

func (*Set[T]) ToSlice

func (s *Set[T]) ToSlice() []T

func (*Set[T]) UnmarshalJSON

func (s *Set[T]) UnmarshalJSON(data []byte) error

func (*Set[T]) Value

func (s *Set[T]) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL