Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply sequentially applies a variadic slice of Option functions to an instance of type 'T'. This allows setting or modifying configurations of 'T' in a functional style. Parameters: - t: A pointer to the instance of type 'T' to be configured. - opts: A variadic slice of Option functions that will be applied to 'T'.
func ApplyErr ¶
ApplyErr sequentially applies a variadic slice of OptionErr functions to an instance of type 'T'. If any OptionErr function returns an error, the process halts and the error is returned. Parameters: - t: A pointer to the instance of type 'T' to be configured. - opts: A variadic slice of OptionErr functions that will be applied to 'T'. Returns: - error: The first error encountered during the application of OptionErr functions, or nil if all apply successfully.
Types ¶
type AnyValue ¶
type AnyValue struct {
Val any // Val is a value of any type.
Err error // Err contains an error if it occurred during the value's processing.
}
AnyValue wraps a value of any type along with an error. It's useful for functions that return a value and an error to be able to package both into a single return value.
func (AnyValue) String ¶
String tries to convert AnyValue's Val to a string. If Val is not a string or if an error is stored in Err, it returns an error. returns the string representation of Val, and an error if the conversion is not possible or an error was previously recorded in Err.
func (AnyValue) StringOrDefault ¶
StringOrDefault attempts to convert AnyValue's Val to a string, returning a default value if the conversion is unsuccessful or an error exists. def: The default string value to return in case of an error or conversion failure. returns the string representation of Val, or the default value 'def' if an error occurs or the conversion is not possible.
type MapSet ¶
type MapSet[T comparable] struct { // contains filtered or unexported fields }
MapSet is a concrete implementation of Set interface, using a map data structure. T: Type parameter which must be comparable.
func InitMapSet ¶
func InitMapSet[T comparable](size int) *MapSet[T]
InitMapSet initializes a MapSet instance with a specified size. T: Type parameter which must be comparable. size: The initial size of the MapSet. returns a pointer to a MapSet instance.
func (*MapSet[T]) Add ¶
func (s *MapSet[T]) Add(val T)
Add includes a new element in the MapSet. val: The value to be added to the MapSet.
func (*MapSet[T]) Delete ¶
func (s *MapSet[T]) Delete(key T)
Delete removes an element from the MapSet. key: The element to be removed from the MapSet.
type Option ¶
type Option[T any] func(t *T) // No return value, modifies 'T' in-place.
Option is a function type that applies a configuration to a type parameter 'T'. Parameters: - t: A pointer to an instance of a generic type 'T' which the option will configure.
type OptionErr ¶
type OptionErr[T any] func(t *T) error // Returns an error which is nil if the application is successful.
OptionErr is like Option but expects an error return. This allows error checking after configuring the given instance of 'T'. Parameters: - t: A pointer to an instance of a generic type 'T' which the option will configure.
type Set ¶
type Set[T comparable] interface { // Add includes an element in the set. Add(key T) // Delete removes an element from the set. Delete(key T) // Exist checks if the set contains an element. Exist(key T) bool // Keys returns all elements in the set. Keys() []T }
Set is an interface for a collection of comparable elements with no duplicate values. T: Type parameter which must be comparable.