set

package
v0.0.0-...-1ed8eff Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reduce

func Reduce[T comparable, U any](s Set[T], f func(U, T) U, initialValue U) U

Reduce reduces the set to a single value.

Types

type Set

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

Set is a set. It is implemented as a map with empty structs.

func FromSlice

func FromSlice[T comparable](s []T) Set[T]

FromSlice creates a new set from a slice.

func Map

func Map[T, U comparable](s Set[T], f func(T) U) Set[U]

Map applies a function to all elements of the set.

func New

func New[T comparable]() Set[T]

New creates a new set.

func (Set[T]) Add

func (s Set[T]) Add(e T)

Add adds an element to the set.

func (Set[T]) Contains

func (s Set[T]) Contains(e T) bool

Contains checks if the set contains an element.

func (Set[T]) Delete

func (s Set[T]) Delete(e T)

Delete deletes an element from the set.

func (Set[T]) Length

func (s Set[T]) Length() int

Length returns the number of elements in the set.

func (Set[T]) Merge

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

Merge merges two sets into a new set.

func (Set[T]) ToSlice

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

ToSlice converts the set to a slice.

Jump to

Keyboard shortcuts

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