Help us shape the future of Go! Take the 2026 Go Developer Survey

collections

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MPL-2.0 Imports: 4 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 container that can hold each item only once and has a fast lookup time.

You can define a new set like this:

var validKeyLengths = collections.Set[int]{
    16: {},
    24: {},
    32: {},
}

You can also use the constructor to create a new set

var validKeyLengths = collections.NewSet[int](16,24,32)

func CollectSet

func CollectSet[T comparable](seq iter.Seq[T]) Set[T]

CollectSet returns a new set containing all of the distinct values from the given sequence.

func NewSet

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

Constructs a new set given the members of type T

func (Set[T]) Has

func (s Set[T]) Has(value T) bool

Has returns true if the item exists in the Set

func (Set[T]) Intersection added in v0.21.0

func (s Set[T]) Intersection(other Set[T]) Set[T]

Intersection returns the common items between the receiver and the given sets.

func (Set[T]) String

func (s Set[T]) String() string

String creates a comma-separated list of all values in the set.

Jump to

Keyboard shortcuts

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