kit

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 1 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 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

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

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

func (av AnyValue) String() (string, error)

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

func (av AnyValue) StringOrDefault(def string) string

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.

func (*MapSet[T]) Exist

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

Exist checks if the MapSet contains a specific element. key: The element to be checked in the MapSet. returns a boolean indicating whether the element exists in the MapSet.

func (*MapSet[T]) Keys

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

Keys gathers all elements from the MapSet. returns a slice of all elements in 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.

Jump to

Keyboard shortcuts

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