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 ¶
- func Map[S comparable, T comparable](mapper result.FlatMapper[S, T], source *Set[S]) result.Result[*Set[T]]
- type Set
- func (set *Set[T]) Add(items ...T) collections.Collection[T]
- func (set *Set[T]) Contains(item T) bool
- func (set *Set[T]) Detect(filter filters.Filter[T]) result.Result[maybe.Maybe[T]]
- func (set *Set[T]) Len() int
- func (set *Set[T]) Remove(item T) collections.Collection[T]
- func (set *Set[T]) Select(filter filters.Filter[T]) result.Result[collections.Collection[T]]
- func (set *Set[T]) String() string
- func (set *Set[T]) ToCollection() collections.Collection[T]
- func (set *Set[T]) ToSlice() []T
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 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 ¶
Contains returns true if the given item is contained in the receiver, otherwise false.
func (*Set[T]) Detect ¶
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 ¶
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]) ToCollection ¶
func (set *Set[T]) ToCollection() collections.Collection[T]
ToCollection returns the receiver as a collections.Collection.