kit

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply[T any](t *T, opts ...Option[T])

Apply applies a variadic list of functional options to a given instance of type T. Parameters: - t: A pointer to the instance to be configured (*T). - opts: A variadic list of functional options (Option[T]). The function iterates over the provided options and applies each one to the instance.

func ApplyErr

func ApplyErr[T any](t *T, opts ...OptionErr[T]) error

ApplyErr applies a variadic list of functional options to a given instance of type T, and returns an error if any option fails. Parameters: - t: A pointer to the instance to be configured (*T). - opts: A variadic list of functional options that may return errors (OptionErr[T]). Returns: - error: An error if any of the options return an error, otherwise nil. The function iterates over the provided options and applies each one to the instance. If any option returns an error, it is immediately returned and no further options are applied.

Types

type MapSet

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

MapSet is a generic implementation of the Set interface using a Go map. It ensures that elements are unique within the set.

func NewMapSet

func NewMapSet[T comparable](size int) *MapSet[T]

NewMapSet creates and returns a new instance of MapSet with an initial capacity. Parameters: - size: The initial capacity of the map (int). Returns: - *MapSet[T]: A pointer to a newly created MapSet.

func (*MapSet[T]) Add

func (s *MapSet[T]) Add(val T)

Add inserts a new element into the MapSet. If the element already exists, it does nothing. Parameters: - val: The value to be added to the set (T).

func (*MapSet[T]) Delete

func (s *MapSet[T]) Delete(key T)

Delete removes an element from the MapSet. If the element does not exist, it does nothing. Parameters: - key: The value to be removed from the set (T).

func (*MapSet[T]) Exist

func (s *MapSet[T]) Exist(key T) bool

Exist checks if a given element exists in the MapSet. Parameters: - key: The value to check for existence in the set (T). Returns: - bool: True if the value exists in the set, false otherwise.

func (*MapSet[T]) Keys

func (s *MapSet[T]) Keys() []T

Keys retrieves all elements from the MapSet as a slice. Returns: - []T: A slice containing all elements in the set.

type Option

type Option[T any] func(t *T)

Option is a generic type for a functional option, which is a function that configures a given instance of type T.

type OptionErr

type OptionErr[T any] func(t *T) error

OptionErr is a generic type for a functional option, which is a function that configures a given instance of type T and may return an error.

type Set

type Set[T comparable] interface {
	Add(key T)        // Adds a new element to the set.
	Delete(key T)     // Deletes an element from the set.
	Exist(key T) bool // Checks if an element exists in the set.
	Keys() []T        // Retrieves all elements in the set as a slice.
}

Set is a generic interface representing a set data structure. It provides methods to add, delete, check the existence of elements, and retrieve all elements as a slice.

Jump to

Keyboard shortcuts

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