sets

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashSet

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

func NewHashSet

func NewHashSet[T comparable](ts ...T) HashSet[T]

func (HashSet[T]) Add

func (s HashSet[T]) Add(elt T) bool

func (HashSet[T]) Choose

func (s HashSet[T]) Choose() optionals.Optional[T]

func (HashSet[T]) Clear

func (s HashSet[T]) Clear()

func (HashSet[T]) Contains

func (s HashSet[T]) Contains(elt T) bool

func (HashSet[T]) Count

func (s HashSet[T]) Count(f func(T) (bool, error)) (int, error)

func (HashSet[T]) CountNoError

func (s HashSet[T]) CountNoError(f func(T) bool) int

func (HashSet[T]) Elements

func (s HashSet[T]) Elements() iter.Seq[T]

func (HashSet[T]) Exists

func (s HashSet[T]) Exists(f func(T) (bool, error)) (bool, error)

func (HashSet[T]) ExistsNoError

func (s HashSet[T]) ExistsNoError(f func(T) bool) bool

func (HashSet[T]) Filter

func (s HashSet[T]) Filter(f func(T) (bool, error)) error

func (HashSet[T]) FilterNoError

func (s HashSet[T]) FilterNoError(f func(T) bool)

func (HashSet[T]) Find

func (s HashSet[T]) Find(
	f func(T) (bool, error),
) (optionals.Optional[T], error)

func (HashSet[T]) FindNoError

func (s HashSet[T]) FindNoError(f func(T) bool) optionals.Optional[T]

func (HashSet[T]) ForAll

func (s HashSet[T]) ForAll(f func(T) (bool, error)) (bool, error)

func (HashSet[T]) ForAllNoError

func (s HashSet[T]) ForAllNoError(f func(T) bool) bool

func (HashSet[T]) IsEmpty

func (s HashSet[T]) IsEmpty() bool

func (HashSet[T]) MarshalJSON

func (s HashSet[T]) MarshalJSON() ([]byte, error)

func (HashSet[T]) Remove

func (s HashSet[T]) Remove(elt T)

func (HashSet[T]) Size

func (s HashSet[T]) Size() int

func (HashSet[T]) ToSlice

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

func (*HashSet[T]) UnmarshalJSON

func (s *HashSet[T]) UnmarshalJSON(data []byte) error

type Set

type Set[T comparable] interface {
	UnmodifiableSet[T]

	// Adds the given element to this set. Returns true if the element was not
	// already a member; false otherwise.
	Add(T) bool

	// Clears all elements from this set.
	Clear()

	// Retains in this set all elements that satisfy f. All other elements are
	// removed.
	//
	// If f returns an error, then iteration stops and that error is returned.
	// Filtering is NOT applied to the element that causes the error. Set elements
	// are processed in the same order as they appear during iteration via
	// [UnmodifiableSet.Elements].
	//
	// This is the imperative version of [setfun.Filter].
	Filter(f func(T) (bool, error)) error

	// Like [Filter], but without support for errors.
	//
	// This is the imperative version of [setfun.FilterNoError].
	FilterNoError(f func(T) bool)

	// Removes the given element from this set. This is a no-op if the element is
	// not a member of this set.
	Remove(T)
}

func NewEmpty

func NewEmpty[T1 comparable, T2 comparable](s UnmodifiableSet[T1]) Set[T2]

Returns a new set having the same underlying implementation as the one given.

type UnmodifiableSet

type UnmodifiableSet[T comparable] interface {
	// Returns an arbitrary element of this set, or None if empty.
	Choose() optionals.Optional[T]

	// Determines whether the given element is a member of this set.
	Contains(T) bool

	// Determines the number of elements in this set that satisfy f.
	//
	// If f returns an error, then iteration stops and that error is returned with
	// the count obtained thus far. If true is returned alongside the error, then
	// this is included in the returned count. Set elements are processed in the
	// same order as they appear during iteration via [Elements].
	Count(f func(T) (bool, error)) (int, error)

	// Like [Count], but without support for errors.
	CountNoError(func(T) bool) int

	// Returns an interator over the elements in this set.
	Elements() iter.Seq[T]

	// Returns true if any element of this set satisfies f.
	//
	// If f returns an error, then iteration stops and that error is returned. Set
	// elements are processed in the same order as they appear during iteration
	// via [Elements].
	Exists(f func(T) (bool, error)) (bool, error)

	// Like [Exists], but without support for errors.
	ExistsNoError(func(T) bool) bool

	// Returns an element of this set that satisfies f.
	//
	// If f returns an error, then iteration stops and that error is returned. Set
	// elements are processed in the same order as they appear during iteration
	// via [Elements].
	Find(func(T) (bool, error)) (optionals.Optional[T], error)

	// Like [Find], but without support for errors.
	FindNoError(func(T) bool) optionals.Optional[T]

	// Returns true if all elements of this set satisfy f.
	//
	// If f returns an error, then iteration stops and that error is returned. Set
	// elements are processed in the same order as they appear during iteration
	// via [Elements].
	ForAll(f func(T) (bool, error)) (bool, error)

	// Like [ForAll], but without support for errors.
	ForAllNoError(func(T) bool) bool

	// Determines whether this set is empty.
	IsEmpty() bool

	// Returns the number of elements in this set.
	Size() int

	// Returns a slice containing all of the elements in this set.
	ToSlice() []T
}

Jump to

Keyboard shortcuts

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