Documentation ¶
Overview ¶
Package util provides utility functions and helpers.
Index ¶
- func Capitalize(s string) string
- func ChunkBy[T any](items []T, chunkSize int) (chunks [][]T)
- func Contains[T comparable](collection []T, element T) bool
- func CopyMap[K, V comparable](m map[K]V) map[K]V
- func CosineSimilarity(matrix1, matrix2 [][]float64) float64
- func Difference[T comparable](list1 []T, list2 []T) ([]T, []T)
- func Filter[T any](collection []T, f func(e T, i int) bool) []T
- func Intersect[T comparable](list1 []T, list2 []T) []T
- func KeyDifference(map1, map2 map[string]any) []string
- func Keys[M ~map[K]V, K comparable, V any](m M) []K
- func Map[T, U any](ts []T, f func(e T, i int) U) []U
- func MergeMaps[M ~map[K]V, K comparable, V any](src ...M) M
- func OmitByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V
- func PTR[T any](v T) *T
- func ParseHTMLAndGetStrippedStrings(htmlContent string) (string, error)
- func StructToMap(obj interface{}) map[string]interface{}
- func SumInt[T int | uint](slice []T) T
- func Uniq[T comparable](collection []T) []T
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Capitalize ¶ added in v0.0.87
Capitalize capitalizes the first letter of the given string. If the input string is empty, it returns the input string itself.
func Contains ¶
func Contains[T comparable](collection []T, element T) bool
Contains checks if the given element is present in the collection.
func CopyMap ¶
func CopyMap[K, V comparable](m map[K]V) map[K]V
CopyMap creates a new copy of the given map and returns it.
func CosineSimilarity ¶ added in v0.0.6
func Difference ¶ added in v0.0.10
func Difference[T comparable](list1 []T, list2 []T) ([]T, []T)
Difference returns the difference between two collections.
func Filter ¶
Filter applies a filtering function to a collection and returns a new slice containing the elements that satisfy the provided predicate function.
func Intersect ¶ added in v0.0.21
func Intersect[T comparable](list1 []T, list2 []T) []T
Intersect returns the intersection between two collections.
func KeyDifference ¶ added in v0.0.9
KeyDifference finds the keys that are present in one map and not in the other map.
func Keys ¶
func Keys[M ~map[K]V, K comparable, V any](m M) []K
Keys returns the keys of the map m. The keys will be an indeterminate order.
func MergeMaps ¶
func MergeMaps[M ~map[K]V, K comparable, V any](src ...M) M
MergeMaps merges multiple maps into a single map and returns the merged result.
func OmitByKeys ¶
func OmitByKeys[K comparable, V any](in map[K]V, keys []K) map[K]V
OmitByKeys creates a new map by omitting key-value pairs from the input map based on the specified keys.
func ParseHTMLAndGetStrippedStrings ¶ added in v0.0.24
ParseHTMLAndGetStrippedStrings parses the HTML content and returns the stripped strings. It uses the goquery package to extract the text from HTML elements.
func StructToMap ¶ added in v0.0.27
func StructToMap(obj interface{}) map[string]interface{}
func Uniq ¶ added in v0.0.10
func Uniq[T comparable](collection []T) []T
Uniq returns a new slice containing unique elements from the given collection.
Types ¶
type Set ¶ added in v0.0.21
type Set[K comparable] struct { // contains filtered or unexported fields }
func SetOf ¶ added in v0.0.21
func SetOf[K comparable](elements ...K) Set[K]
SetOf returns a new set initialized with the given elements
func (Set[K]) Clear ¶ added in v0.0.21
func (s Set[K]) Clear()
Clear removes all elements from the set.
func (Set[K]) Each ¶ added in v0.0.21
func (s Set[K]) Each(fn func(key K))
Each calls 'fn' on every element in the set in no particular order.
func (Set[K]) Put ¶ added in v0.0.21
func (s Set[K]) Put(element K)
Put adds the element to the set.
func (Set[K]) Remove ¶ added in v0.0.21
func (s Set[K]) Remove(element K)
Remove removes the element from the set.