utils

package
v0.0.0-...-3968f94 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var URL_RE = regexp.MustCompile(`^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)`)

Functions

func AppendToFirst

func AppendToFirst[T any](arr []T, ele T) []T

func Contain

func Contain[T comparable](slice []T, target T) bool

func DeDup

func DeDup[T comparable, TS ~[]T](input TS) []T

func DeRef2

func DeRef2[T any](input *T, err error) (T, error)

func DecodeLength

func DecodeLength(bytes []byte) (int, int, error)

func EncodeLength

func EncodeLength(bytes *[]byte, length int)

func Find

func Find[T any, TS ~[]T](slice TS, predicate func(T) bool) (T, bool)

func FindIndex

func FindIndex[T any, TS ~[]T](slice TS, predicate func(T) bool) int

func FindIndexByValue

func FindIndexByValue[T comparable, TS ~[]T](slice TS, predicate T) int

func MakeWebsocketURL

func MakeWebsocketURL(endpoint string) (string, error)

MakeWebsocketURL generates a WebSocket URL based on the provided endpoint

func Map

func Map[T any, O any, TS ~[]T](input TS, mapper func(T) O) []O

func MapInt

func MapInt[T constraints.Integer, O constraints.Integer, TS ~[]T](input TS) []O

func MapWithError

func MapWithError[T any, O any, TS ~[]T](input TS, mapper func(T) (O, error)) ([]O, error)

func MergeList

func MergeList[T any, TS ~[]T](args ...TS) []T

func PowInt

func PowInt[T uint8 | int8 | uint16 | int16 | uint32 | int32 | uint64 | int64 | int | uint](base T, p int) T

func RemoveEle

func RemoveEle[T comparable](arr []T, ele func(T) bool) []T

func RemoveIndex

func RemoveIndex[T any](arr []T, index int) []T

func StructToMap

func StructToMap(obj any) map[string]any

StructToMap converts a struct to a map[string]interface{}

func SumInt

func SumInt[T uint8 | int8 | uint16 | int16 | uint32 | int32 | uint64 | int64 | int | uint, O any](base []O, callback func(O) T) T

Types

type KVMap

type KVMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewKVMap

func NewKVMap[K comparable, V any]() *KVMap[K, V]

func (*KVMap[K, V]) Entries

func (m *KVMap[K, V]) Entries() (keys []K, values []V)

func (*KVMap[K, V]) InsertOrUpdate

func (m *KVMap[K, V]) InsertOrUpdate(key K, value V, update func(*V))

func (*KVMap[K, V]) Keys

func (m *KVMap[K, V]) Keys() (out []K)

func (*KVMap[K, V]) Values

func (m *KVMap[K, V]) Values() (out []V)

type Set

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

func NewSet

func NewSet[T comparable]() *Set[T]

func (*Set[T]) Add

func (s *Set[T]) Add(value T)

func (*Set[T]) AddIfNotExists

func (s *Set[T]) AddIfNotExists(value T)

func (*Set[T]) Exists

func (s *Set[T]) Exists(value T) bool

func (*Set[T]) Len

func (s *Set[T]) Len() int

func (*Set[T]) List

func (s *Set[T]) List() []T

func (*Set[T]) Remove

func (s *Set[T]) Remove(value T)

Jump to

Keyboard shortcuts

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