collection

package
v0.19.5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToMap added in v0.17.2

func ToMap[K comparable, V any](s []V, key func(V) K) map[K]V

ToMap is a utility function that converts the slice s to a map using key to retrieve map keys.

func ToSlice added in v0.17.2

func ToSlice[K comparable, V any](m map[K]V) []V

ToSlice is a utility function that converts the map m to a slice of m's values. The returned slices order is undefined.

Types

type Set

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

Set is a collection that only contains unique elements.

func MapSet

func MapSet[G any, T comparable](c []G, f func(G) T) Set[T]

MapSet converts c to a new set. f is used to extract the value for representing each element of c.

func NewSet

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

NewSet creates an empty Set.

func NewSetFrom

func NewSetFrom[T comparable](elements ...T) Set[T]

NewSetFrom creates a Set from a list of elements.

func (Set[T]) Add

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

Add stores a new element in the Set if wasn't contained yet.

func (Set[T]) Contains

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

Contains checks if an element is contained in the Set.

func (Set[T]) Delete

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

Delete removes an element from the Set if it existed.

func (Set[T]) ToSlice

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

ToSlice generates a new slice with all elements in the Set. Order is non deterministic.

Jump to

Keyboard shortcuts

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