set

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package set implements support for a generic unordered Set. A Set is a Collection that wraps an underlying hash map and provides convenience methods and syntatic sugar on top of it.

Set elements are unique and unordered by default. However Sets share some methods with other collections and implement the Collection interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable](s ...[]T) *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(v T)

func (*Set[T]) Apply

func (s *Set[T]) Apply(f func(T) T) *Set[T]

Apply applies a function to each element in the set.

func (*Set[T]) Clone

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

Clone returns a copy of the collection. This is a shallow clone.

func (*Set[T]) Contains

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

Contains returns true if the set contains the value.

func (*Set[T]) ContainsFunc

func (s *Set[T]) ContainsFunc(f func(T) bool) bool

ContainsFunc returns true if the set contains a value that satisfies the predicate.

func (*Set[T]) Count

func (s *Set[T]) Count(f func(T) bool) int

func (*Set[T]) Diff

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

Difference returns a new set containing the difference of the current set and the passed in set.

func (*Set[T]) Equals

func (s *Set[T]) Equals(s2 *Set[T]) bool

Equals returns true if the two sets contain the same elements.

func (*Set[T]) Filter

func (s *Set[T]) Filter(f func(T) bool) *Set[T]

Filter is an alias for collection.Filter

func (*Set[T]) FilterNot

func (s *Set[T]) FilterNot(f func(T) bool) *Set[T]

FilterNot is an alias for collection.FilterNot

func (*Set[T]) ForAll

func (s *Set[T]) ForAll(f func(T) bool) bool

ForAll is an alias for collection.ForAll

func (*Set[T]) Intersection

func (s *Set[T]) Intersection(s2 *Set[T]) *Set[T]

Intersection returns a new set containing the intersection of the current set and the passed in set.

func (*Set[T]) IsEmpty

func (s *Set[T]) IsEmpty() bool

IsEmpty returns true if the set is empty.

func (*Set[T]) Length

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

func (*Set[T]) New

func (s *Set[T]) New(s2 ...[]T) collection.Collection[T]

func (*Set[T]) NonEmpty

func (s *Set[T]) NonEmpty() bool

NonEmpty returns true if the set is not empty.

func (*Set[T]) Partition

func (s *Set[T]) Partition(f func(T) bool) (*Set[T], *Set[T])

Partition is an alias for collection.Partition

func (*Set[T]) Random

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

func (*Set[T]) Remove

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

Remove removes a value from the set.

func (*Set[T]) String

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

implement the Stringer interface

func (*Set[T]) ToSlice

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

func (*Set[T]) Union

func (s *Set[T]) Union(s2 *Set[T]) *Set[T]

Union returns a new set containing the union of the current set and the passed in set.

func (*Set[T]) Values

func (s *Set[T]) Values() iter.Seq[T]

Jump to

Keyboard shortcuts

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