Documentation ¶
Overview ¶
Set provides a collection of unique elements of a particular type T that are printable, type convertible and have verifiable validity. Element represents an element of a set that has a unique value and is printable. SetElements provides an iterator for all elements of a set intended for SetFactory.NewSet.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewElements ¶
func NewElements[T comparable, E any](elements []E) (iter iters.Iterator[Element[T]])
NewElements returns an iterator of interface-type sets.Element[T] based from a slice of non-interface-type Elements[T comparable].
func PrintAsString ¶
Types ¶
type Element ¶
type Element[T comparable] interface { Value() (value T) fmt.Stringer }
Element represents an element of a set that has a unique value and is printable. set element values are unique but not necessarily ordered. set.SetElement is an implementation.
type ElementFull ¶
type ElementFull[T comparable] interface { Element[T] Description() (full string) }
type ElementIterator ¶
type ElementIterator[T comparable] interface { Elements() iters.Iterator[*Element[T]] }
ElementIterator provides an iterator for all elements of a set intended for SetFactory.NewSet.
type ElementSlice ¶
type ElementSlice[T comparable, E any] struct { // contains filtered or unexported fields }
ElementSlice ToDo
func (*ElementSlice[T, E]) Cancel ¶
func (iter *ElementSlice[T, E]) Cancel() (err error)
func (*ElementSlice[T, E]) Next ¶
func (iter *ElementSlice[T, E]) Next(isSame iters.NextAction) (value Element[T], hasValue bool)
type Set ¶
type Set[T comparable] interface { // IsValid returns whether value is part of this set IsValid(value T) (isValid bool) // Element returns the element representation for value or // nil if value is not an element of the set. Element(value T) (element Element[T]) // StringT returns a string representation for an element of this set. // if value is not a valid element, a fmt.Printf value is output like ?'%v' StringT(value T) (s string) Description(value T) (s string) fmt.Stringer }
Set provides a collection of unique elements of a particular type T that are printable, type convertible and have verifiable validity. A set stores unique values without any particular order. The reasons for using a set over const are:
- set memberhip enforcement
- available string representation for elements
- additional fields or methods assigned to elements
- optional type safety
Usage:
const IsSame NextAction = 0 type NextAction uint8 func (na NextAction) String() (s string) {return nextActionSet.StringT(na)} var nextActionSet = set.NewSet(yslices.ConvertSliceToInterface[ set.Element[NextAction], parli.Element[NextAction], ]([]set.Element[NextAction]{{ValueV: IsSame, Name: "IsSame"}}))
type SetElement ¶
type SetElement[T comparable] struct { ValueV T Name string }
func (*SetElement[T]) String ¶
func (pv *SetElement[T]) String() (s string)
func (*SetElement[T]) Value ¶
func (pv *SetElement[T]) Value() (value T)
type SetElementFull ¶
type SetElementFull[T comparable] struct { ValueV T Name string // key that maps to this enumeration value Full string // sentence describing this flag }
SetElementFull is an value or flag-value item of an enumeration container.
- K is the type of a unique key mapping one-to-one to an enumeration value
- V is the type of the internally used value representation
func (*SetElementFull[T]) Description ¶
func (item *SetElementFull[T]) Description() (desc string)
func (*SetElementFull[T]) String ¶
func (item *SetElementFull[T]) String() (s string)
func (*SetElementFull[T]) Value ¶
func (item *SetElementFull[T]) Value() (value T)
type SetFactory ¶
type SetFactory[T comparable] interface { // NewSet returns a set of a finite number of elements. // Usage: // // const IsSame NextAction = 0 // type NextAction uint8 // func (na NextAction) String() (s string) {return nextActionSet.StringT(na)} // var nextActionSet = set.NewSet(yslices.ConvertSliceToInterface[ // set.Element[NextAction], // parli.Element[NextAction], // ]([]set.Element[NextAction]{{ValueV: IsSame, Name: "IsSame"}})) NewSet(elements []Element[T]) (interfaceSet Set[T]) }
type SetImpl ¶
type SetImpl[T comparable] struct { // contains filtered or unexported fields }
SetImpl holds a multiple-selection function argument that has printable representation. PrintableEnum allows finite selection function arguments to have meaningful names and makes those names printable.