set

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package set defines the Set struct, an implementation of the Collection interface, and supporting functions. A Set is a collection of unique comparable items.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map

func Map[S comparable, T comparable](
	mapper result.FlatMapper[S, T],
	source *Set[S],
) result.Result[*Set[T]]

Map the given Set using the given mapper and filter, returning a Set of mapped items, never nil; an error is returned if either the mapper or the filter fails.

Types

type Set

type Set[T comparable] struct {
	*bag.Bag[T]
	// contains filtered or unexported fields
}

Set defines the structure of a set collection, an implementation of the collections.Collection interface. A Set is a hashed collection of comparable items; duplicates are not allowed. This type is not thread-safe.

func New

func New[T comparable](size int) *Set[T]

New creates a Set of the given size.

func NewFrom

func NewFrom[T comparable](items ...T) *Set[T]

NewFrom creates a Set containing the given items.

func NewFromCollection

func NewFromCollection[T comparable](source collections.Collection[T]) *Set[T]

NewFromCollection creates a Set containing the items in the given Collection.

func NewWithAccessor

func NewWithAccessor[T comparable](size int) (*Set[T], func() map[T]int)

NewWithAccessor creates a Set of the given size, along with an accessor function. The accessor function is intended for use by composite types that need direct access to the Set's implementation; the accessor function should not be shared.

func (*Set[T]) Add

func (set *Set[T]) Add(items ...T) collections.Collection[T]

Add the given items to the receiver. Returns the receiver as a collections.Collection. collections.Collection.

func (*Set[T]) Contains

func (set *Set[T]) Contains(item T) bool

Contains returns true if the given item is contained in the receiver, otherwise false.

func (*Set[T]) Detect

func (set *Set[T]) Detect(filter filters.Filter[T]) result.Result[maybe.Maybe[T]]

Detect queries the receiver for an item matching the given filter. Returns the detected item, and true when found, otherwise the zero value and false; an error is returned if the filter fails.

func (*Set[T]) Len

func (set *Set[T]) Len() int

Len returns the length of the receiver; an empty receiver has a length of zero.

func (*Set[T]) Remove

func (set *Set[T]) Remove(item T) collections.Collection[T]

Remove the given item from the receiver. If the item does not exist the receiver is unchanged.Returns the receiver as a collections.Collection.

func (*Set[T]) Select

func (set *Set[T]) Select(filter filters.Filter[T]) result.Result[collections.Collection[T]]

Select returns the receiver's items that match the given filter; an error is returned if the filter fails. The returned collection is the same species as the receiver, and never nil.

func (*Set[T]) String

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

String returns a human-readable representation of the receiver.

func (*Set[T]) ToCollection

func (set *Set[T]) ToCollection() collections.Collection[T]

ToCollection returns the receiver as a collections.Collection.

func (*Set[T]) ToSlice

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

ToSlice returns a new slice of items contained in the receiver. Changes to the slice do not affect the contents of the receiver.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳