set

package
v0.0.46-2e8eb6d Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package set provides a bog standard set implementation for Go, just a wrapper around a map[T comparable]struct{} Most set methods mutate the set and return it to facilitate method chaining. Not thread safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSeq

func ToSeq[T any](v ...T) iter.Seq[T]

ToSeq concisely converts values into an iter.Seq. The values are not made unique. Not directly related to sets so may be moved out of this package but set.ToSeq(1,2,3) is more concise than slices.Values([]int{1,2,3}).

Types

type Set

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

func From

func From[T comparable](vals ...T) Set[T]

From creates a set from the comparable values passed in.

func FromSeq

func FromSeq[T comparable](vals iter.Seq[T]) Set[T]

FromSeq creates a set from the comparable values passed in via iter.Seq.

func (Set[T]) Add

func (a Set[T]) Add(values ...T) Set[T]

Add adds values to the set

func (Set[T]) All

func (a Set[T]) All() iter.Seq[T]

All returns an iterator over all elements in the set

func (Set[T]) Difference

func (a Set[T]) Difference(b iter.Seq[T]) Set[T]

Difference returns the difference of the set and sequence

func (Set[T]) Has

func (a Set[T]) Has(values ...T) bool

Has returns a boolean indicating whether the set contains all of the values.

func (Set[T]) HasAll

func (a Set[T]) HasAll(b iter.Seq[T]) bool

HasAll returns a boolean indicating whether the set contains all of the sequence.

func (Set[T]) HasAny

func (a Set[T]) HasAny(b iter.Seq[T]) bool

HasAny returns a boolean indicating whether the set contains any of the sequence.

func (Set[T]) Intersects

func (a Set[T]) Intersects(b iter.Seq[T]) Set[T]

Intersects returns a new set that is the intersection of the set and sequence

func (Set[T]) Union

func (a Set[T]) Union(b iter.Seq[T]) Set[T]

Union returns the union of the set and sequence

Jump to

Keyboard shortcuts

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