dp - Go Documentation Server window.initFuncs = []; var goVersion = "go1.23.2";
...
submit search
document.ANALYSIS_DATA = null; document.CALLGRAPH = null;
import "github.com/SmikeForYou/dp"
func Chanalize[T any](values ...T) <-chan T
func ChanalizeCb[T any](callback func(), values ...T) <-chan T
func Chunk[T any](chunkSize int, iterable ...T) [][]T
func Compress[T any](data []T, compressor []bool) []T
func Cycle[T any](iterable ...T) (<-chan T, func())
func DerefArray[T any](arr []*T) []T
func EnumerateChan[T any](ch <-chan T) <-chan Enumerated[T]
func FanIn[T any](channels ...<-chan T) <-chan T
func FanOut[T any](source <-chan T, channels ...chan T)
func Filter[T any](data []T, callback func(elem T, index int) bool) []T
func FilterChan[T any](data <-chan T, callback func(elem T) bool) <-chan T
func GetFieldByTag(in any, tag string, tagValue string) (reflect.StructField, reflect.Value, error)
func In[T comparable](elem T, data []T) int
func Map[T, K any](data []T, callback func(elem T, index int) K) []K
func MapChan[T, K any](data <-chan T, callback func(elem T) K) <-chan K
func Max[T constraints.Ordered](elems ...T) T
func Min[T constraints.Ordered](elems ...T) T
func Permutations[T comparable](data []T) [][]T
func RefArray[T any](arr []T) []*T
func ReleaseChanel[T any](chanel <-chan T) []T
func Repeat[T any](value T, count int) []T
func SetTimeout(timeout time.Duration, fn func())
func Sort[T any](data []T, compare func(T, T) bool, reverse bool) []T
func StructToArr(in any, tag string) ([]any, error)
func StructToMap(in any, tag string) (map[string]any, error)
func Sum[T constraints.Ordered](data ...T) T
func Timer[T any](lap time.Duration, val T) (<-chan T, func())
func Zip[T any](iterables ...[]T) [][]T
func ZipChan[T any](chanels ...<-chan T) <-chan []T
func NewCache[K comparable, V any]() Cache[K, V]
func NewCacheFromArr[K comparable, V any](data []V, visitor func(elem V) (K, V)) Cache[K, V]
func (c Cache[K, V]) Exists(key K) bool
func (c Cache[K, V]) Get(key K) (V, bool)
func (c Cache[K, V]) GetWithCallback(key K, onFail func(key K) (V, bool)) (V, bool)
func (c Cache[K, V]) Push(key K, val V)
func (c Cache[K, V]) Remove(key K)
func GroupBy[T any](iterable []T, keyExtractor func(elem T) any) []Grouper[T]
func NewIterator[T any](data []T) Iterator[T]
func (receiver *Iterator[T]) Elem() T
func (receiver *Iterator[T]) Items() (int, T)
func (receiver *Iterator[T]) Next() bool
func NewTempCache[K comparable, V any]() TempCache[K, V]
func (tc TempCache[K, V]) Get(key K) (V, bool)
func (tc TempCache[K, V]) Push(key K, val V, ttl time.Duration)
func (tc TempCache[K, V]) Remove(key K)
caches.go chan_func.go func.go struct_func.go utils.go
func AccumulateChan ¶
func AccumulateChan[T constraints.Ordered](data <-chan T, fun func(total, elem T) T, initial T) <-chan T
AccumulateChan accumulates results of other binary functions which are mentioned in the function parameter. Parameters: - data: The input channel to accumulate. - fun: The function to use for accumulation. - initial: The initial value for accumulation. Returns: - A channel that will receive the accumulated values.
func Chanalize[T any](values ...T) <-chan T
Chanalize converts an array of values to a channel with these values. Parameters: - values: The values to send to the channel. Returns: - A channel that will receive the values.
func ChanalizeCb ¶
func ChanalizeCb[T any](callback func(), values ...T) <-chan T
ChanalizeCb converts an array of values to a channel with these values and runs a callback function after all values are sent. Parameters: - callback: The function to call after all values are sent. - values: The values to send to the channel. Returns: - A channel that will receive the values.
func Chunk[T any](chunkSize int, iterable ...T) [][]T
Chunk splits a slice into chunks. Parameters: - chunkSize: The size of each chunk. - iterable: The slice to split into chunks. Returns: - A slice of chunks.
func Compress[T any](data []T, compressor []bool) []T
Compress gets two slices and adds values from the first slice to the result if the value in the second slice with the same index is true. If the slice lengths are not equal, the shorter one will be taken. Parameters: - data: The slice of elements to compress. - compressor: The slice of booleans to determine which elements to include. Returns: - A slice of compressed elements.
func Cycle[T any](iterable ...T) (<-chan T, func())
Cycle will cyclically return values from an iterable to a channel one by one until the channel is closed. Parameters: - iterable: The values to cycle through. Returns: - A channel that will receive the values cyclically. - A function to stop the cycling.
func DerefArray ¶
func DerefArray[T any](arr []*T) []T
DerefArray converts an array of pointers to an array of values. Parameters: - arr: The input array of pointers. Returns: - An array of values.
func EnumerateChan ¶
func EnumerateChan[T any](ch <-chan T) <-chan Enumerated[T]
EnumerateChan wraps a provided channel and adds an index number to each channel value. Parameters: - ch: The input channel to enumerate. Returns: - A channel that will receive the enumerated values.
func FanIn[T any](channels ...<-chan T) <-chan T
FanIn aggregates several channels into one. Fan-in pattern implementation. Parameters: - channels: The input channels to aggregate. Returns: - A channel that will receive the aggregated values.
func FanOut[T any](source <-chan T, channels ...chan T)
FanOut broadcasts messages from a source channel to target channels. Parameters: - source: The source channel to broadcast from. - channels: The target channels to broadcast to.
func Filter[T any](data []T, callback func(elem T, index int) bool) []T
Filter filters values of a slice using a callback function. Parameters: - data: The slice of elements to filter. - callback: A function to determine if an element should be included. Returns: - A slice of filtered elements.
func FilterChan ¶
func FilterChan[T any](data <-chan T, callback func(elem T) bool) <-chan T
FilterChan filters channel values using a callback function. Parameters: - data: The input channel to filter. - callback: The function to use for filtering values. Returns: - A channel that will receive the filtered values.
func GetFieldByTag ¶
func GetFieldByTag(in any, tag string, tagValue string) (reflect.StructField, reflect.Value, error)
GetFieldByTag returns the struct field and value of the field with the given tag. If tagValue is empty, the first field with the given tag is returned. Parameters: - in: The input struct to be searched. - tag: The tag used to filter the struct fields. - tagValue: The specific tag value to search for. Returns: - The struct field and its value. - An error if the input is not a struct or the tag is not found.
func In[T comparable](elem T, data []T) int
In returns the index of the first appearance of an element in a slice. Returns -1 if the element does not appear. Parameters: - elem: The element to search for. - data: The slice to search in. Returns: - The index of the element, or -1 if not found.
func Map[T, K any](data []T, callback func(elem T, index int) K) []K
Map applies a callback function to each element of a slice and returns a new slice. Parameters: - data: The slice of elements to map. - callback: A function to apply to each element. Returns: - A slice of mapped elements.
func MapChan[T, K any](data <-chan T, callback func(elem T) K) <-chan K
MapChan applies a callback function to each value of a channel and returns a new channel with the results. Parameters: - data: The input channel to map. - callback: The function to apply to each value. Returns: - A channel that will receive the mapped values.
func Max[T constraints.Ordered](elems ...T) T
Max returns the maximum value of a slice. Parameters: - elems: The elements to find the maximum value of. Returns: - The maximum value.
func Min[T constraints.Ordered](elems ...T) T
Min returns the minimum value of a slice. Parameters: - elems: The elements to find the minimum value of. Returns: - The minimum value.
func Permutations ¶
func Permutations[T comparable](data []T) [][]T
Permutations returns all permutations of a slice. Parameters: - data: The slice of elements to permute. Returns: - A slice of permutations.
func RefArray[T any](arr []T) []*T
RefArray converts an array of values to an array of pointers. Parameters: - arr: The input array of values. Returns: - An array of pointers.
func ReleaseChanel ¶
func ReleaseChanel[T any](chanel <-chan T) []T
ReleaseChanel reads all values from a channel and returns an array of these values. Parameters: - chanel: The channel to read values from. Returns: - An array of values read from the channel.
func Repeat[T any](value T, count int) []T
Repeat copies a value to a slice several times. Parameters: - value: The value to repeat. - count: The number of times to repeat the value. Returns: - A slice of repeated values.
func SetTimeout ¶
func SetTimeout(timeout time.Duration, fn func())
SetTimeout executes a function after a timeout. Parameters: - timeout: The duration to wait before executing the function. - fn: The function to execute.
func Sort[T any](data []T, compare func(T, T) bool, reverse bool) []T
Sort performs a bubble sort on the provided data. Parameters: - data: The slice of elements to sort. - compare: A function to compare two elements. - reverse: A boolean indicating whether to sort in reverse order. Returns: - A sorted slice of elements.
func StructToArr ¶
func StructToArr(in any, tag string) ([]any, error)
StructToArr converts a struct to a slice of values of struct field. It uses tags on struct fields to decide which fields to add to the returned slice. Parameters: - in: The input struct to be converted. - tag: The tag used to filter the struct fields. Returns: - A slice of struct field values. - An error if the input is not a struct.
func StructToMap ¶
func StructToMap(in any, tag string) (map[string]any, error)
StructToMap converts a struct to a map using the struct's tags. It uses tags on struct fields to decide which fields to add to the returned map. Parameters: - in: The input struct to be converted. - tag: The tag used to filter the struct fields. Returns: - A map with keys as tag values and values as struct field values. - An error if the input is not a struct.
func Sum[T constraints.Ordered](data ...T) T
Sum sums all values of a slice. Parameters: - data: The slice of elements to sum. Returns: - The sum of the elements.
func Timer[T any](lap time.Duration, val T) (<-chan T, func())
Timer will send a value with a delay to a channel until the channel is closed. Parameters: - lap: The duration to wait between sending values. - val: The value to send. Returns: - A channel that will receive the values. - A function to stop the timer.
func Zip[T any](iterables ...[]T) [][]T
Zip aggregates values from several slices. Parameters: - iterables: The slices to aggregate. Returns: - A slice of aggregated values.
func ZipChan[T any](chanels ...<-chan T) <-chan []T
ZipChan aggregates values from several channels into portions and sends them to a result channel. Parameters: - chanels: The input channels to aggregate. Returns: - A channel that will receive the aggregated values.
Cache is a generic map-based cache. K is the type of the keys, and V is the type of the values.
type Cache[K comparable, V any] map[K]V
func NewCache[K comparable, V any]() Cache[K, V]
NewCache creates a new empty Cache.
func NewCacheFromArr ¶
func NewCacheFromArr[K comparable, V any](data []V, visitor func(elem V) (K, V)) Cache[K, V]
NewCacheFromArr creates a new Cache from a slice of values. The visitor function is used to generate the key-value pairs for the cache.
func (c Cache[K, V]) Exists(key K) bool
Exists checks if a key exists in the Cache.
func (c Cache[K, V]) Get(key K) (V, bool)
Get retrieves a value from the Cache by key. It returns the value and a boolean indicating whether the key was found.
func (Cache[K, V]) GetWithCallback ¶
func (c Cache[K, V]) GetWithCallback(key K, onFail func(key K) (V, bool)) (V, bool)
GetWithCallback retrieves a value from the Cache by key. If the key is not found, the onFail callback is called to provide a value.
func (c Cache[K, V]) Push(key K, val V)
Push adds a key-value pair to the Cache.
func (c Cache[K, V]) Remove(key K)
Remove deletes a key-value pair from the Cache by key.
type Enumerated ¶
Enumerated is a wrapper struct for the EnumerateChan function.
type Enumerated[T any] struct { // contains filtered or unexported fields }
Grouper is a grouping struct for GroupBy.
type Grouper[T any] struct { Key any Group []T }
func GroupBy[T any](iterable []T, keyExtractor func(elem T) any) []Grouper[T]
GroupBy returns consecutive keys and groups from the iterable. Parameters: - iterable: The slice of elements to group. - keyExtractor: A function to extract the key for each element. Returns: - A slice of Grouper structs.
Iterator implements the iterator pattern without using unsafe code.
type Iterator[T any] struct { // contains filtered or unexported fields }
func NewIterator ¶
func NewIterator[T any](data []T) Iterator[T]
NewIterator creates a new Iterator. Parameters: - data: The slice of elements to iterate over. Returns: - A new Iterator.
func (receiver *Iterator[T]) Elem() T
Elem returns the current element of the iteration. Returns the current element.
func (receiver *Iterator[T]) Items() (int, T)
Items returns the current index of the iteration and the element at that index. Returns the current index and element.
func (receiver *Iterator[T]) Next() bool
Next advances the Iterator to the next element. Returns true if there are more elements to iterate over. Returns false if the end of the slice is reached.
TempCache is a cache with time-based expiration for its values. K is the type of the keys, and V is the type of the values.
type TempCache[K comparable, V any] struct { // contains filtered or unexported fields }
func NewTempCache ¶
func NewTempCache[K comparable, V any]() TempCache[K, V]
NewTempCache creates a new empty TempCache.
func (tc TempCache[K, V]) Get(key K) (V, bool)
Get retrieves a value from the TempCache by key. If the value has expired, it is removed from the cache and a zero value is returned.
func (tc TempCache[K, V]) Push(key K, val V, ttl time.Duration)
Push adds a key-value pair to the TempCache with a time-to-live (TTL).
func (tc TempCache[K, V]) Remove(key K)
Remove deletes a key-value pair from the TempCache by key.
Build version go1.23.2.
Except as noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code is licensed under a BSD license.
Terms of Service | Privacy Policy