collections

package module
v0.0.0-...-5baf374 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 3 Imported by: 16

README

go-collections

Go Report Card GitHub go.mod Go version Slack Invite

A library with generic data structures for common collection operations.

Status

Consider this project to be in alpha. The API is not stable and may change at any time.

Overview

collections.TaggedValue a set of tags associated with a value

collections.TaggedValueSet provides methods for performing set operations on an arbitrary set of tagged values

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TaggedValue

type TaggedValue[T any] struct {
	Value T
	Tags  []string
}

TaggedValue holds an arbitrary value with associated tags

func NewTaggedValue

func NewTaggedValue[T any](value T, tags ...string) TaggedValue[T]

NewTaggedValue returns a tagged value, that can be added, for example, to a TaggedValueSet collection

func (TaggedValue[T]) HasTag

func (t TaggedValue[T]) HasTag(tags ...string) bool

HasTag indicates the TaggedValue has a tag matching one or more of the provided arguments

type TaggedValueSet

type TaggedValueSet[T comparable] []TaggedValue[T]

TaggedValueSet is a utility to handle a sorted set of tagged items including basic filtering

func (TaggedValueSet[T]) HasTag

func (t TaggedValueSet[T]) HasTag(tags ...string) bool

HasTag indicates this set contains one or more items matching any of the provided tags

func (TaggedValueSet[T]) HasValue

func (t TaggedValueSet[T]) HasValue(value ...T) bool

HasValue indicates any of the provided values is present in this set

func (TaggedValueSet[T]) Join

func (t TaggedValueSet[T]) Join(taggedValues ...TaggedValue[T]) TaggedValueSet[T]

Join returns a new set of values, combining this set and the provided values, omitting duplicates

func (TaggedValueSet[T]) Remove

func (t TaggedValueSet[T]) Remove(tags ...string) TaggedValueSet[T]

Remove returns a new set of values, excluding those with any of the provided tags

func (TaggedValueSet[T]) Select

func (t TaggedValueSet[T]) Select(tags ...string) TaggedValueSet[T]

Select returns a new set of values matching any of the provided tags, ordered by the provided tags

func (TaggedValueSet[T]) Tags

func (t TaggedValueSet[T]) Tags() (tags []string)

Tags returns the unique set of tags from all entries

func (TaggedValueSet[T]) Values

func (t TaggedValueSet[T]) Values() []T

Values returns a slice containing the values in the set

Jump to

Keyboard shortcuts

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