helper

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToRunes added in v0.1.14

func BytesToRunes(b []byte) []rune

func Filter

func Filter[T any](s []T, f func(T) bool) []T

Filter filters values from a slice using a filter function. It returns a new slice with only the elements of s for which f returned true.

func Includes

func Includes[T comparable](slice []T, value T) bool

Includes - given a slice of type T and a value of type T, determines whether the value is contained by the slice.

func IsPtr

func IsPtr(v any) bool

func Keys

func Keys[K comparable, V any](m map[K]V) []K

Keys returns the keys of the map m in a slice. The keys will be returned in an unpredictable order. This function has two type parameters, K and V. Map keys must be comparable, so key has the predeclared constraint comparable. Map values can be any type.

func Merge

func Merge[T any](slices ...[]T) (mergedSlice []T)

Merge - receives slices of type T and merges them into a single slice of type T.

func RemoveZWNBS added in v0.1.16

func RemoveZWNBS[T string | []byte](input T) T

func RunesToBytes added in v0.1.14

func RunesToBytes(runes []rune) []byte

func Sort

func Sort[T constraints.Ordered](s []T)

Sort - sorts given a slice of any order-able type T The constraints.Ordered constraint in the Sort() function guarantees that the function can sort values of any type supporting the operators <, <=, >=, >.

func SplitAfter added in v0.1.4

func SplitAfter(str string, sep []rune, min int) ([]string, error)

func Sum

func Sum[K comparable, V constraints.Float | constraints.Integer](m map[K]V) V

Sum sums the values of map containing numeric or float values

Types

type Set

type Set[T comparable] map[T]struct{}

Set is a set of any values.

func MakeSet added in v0.1.4

func MakeSet[T comparable]() Set[T]

MakeSet returns a set of some element type.

func (Set[T]) Add

func (s Set[T]) Add(v T)

Add adds v to the set s. If v is already in s this has no effect.

func (Set[T]) All added in v0.1.5

func (s Set[T]) All() []T

All return all elements.

func (Set[T]) Contains

func (s Set[T]) Contains(v T) bool

Contains reports whether v is in s.

func (Set[T]) Delete

func (s Set[T]) Delete(v T)

Delete removes v from the set s. If v is not in s this has no effect.

func (Set[T]) Len

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

Len reports the number of elements in s.

Jump to

Keyboard shortcuts

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