helpers

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package helpers provides generic helper functions with no external imports

Package helpers provides generic helper functions with no external imports

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[T any](ss []T, test func(T) bool) (r []T)

Filter returns a new slice with only the elements that pass the test.

func Find

func Find[T any](ss []T, test func(T) bool) (r T)

Find returns the first element that passes the test.

func GetCRCHash

func GetCRCHash(text string) uint32

GetCRCHash returns the computed CRC32 Sum of a given string

func GetCryptoHash

func GetCryptoHash(data io.ReadCloser, hashName crypto.Hash) (string, error)

GetCryptoHash returns the computed SHA256 Sum of a given file

func Insert

func Insert[T any](slice []T, index int, element T) []T

Insert returns a new slice with the element inserted at the given index.

func MatchRegex

func MatchRegex(regex *regexp.Regexp, str string) (func(string) string, error)

MatchRegex wraps a get function around a substring match.

func MergeMap

func MergeMap[T any](m1, m2 map[string]T) (r map[string]T)

MergeMap merges map m2 with m1 overwriting common values with m2's values.

func MergeMapRecursive

func MergeMapRecursive(m1, m2 map[string]interface{}) (r map[string]interface{})

MergeMapRecursive recursively (nestedly) merges map m2 with m1 overwriting common values with m2's values.

func RemoveMatches

func RemoveMatches[T any](ss []T, test func(T) bool) (r []T)

RemoveMatches removes the given element from the slice that matches the test.

func Retry

func Retry(fn func() error, retries int, delay time.Duration) (err error)

Retry will retry a function until it succeeds or the timeout is reached, timeout == retries * delay.

func Reverse

func Reverse[T any](s []T) (r []T)

Reverse returns a new slice with the elements in reverse order.

func SliceContains

func SliceContains[T comparable](s []T, e T) bool

SliceContains returns true if the given element is in the slice.

func TransformMapKeys

func TransformMapKeys[T any](m map[string]T, transform func(string) string) (r map[string]T)

TransformMapKeys takes a map and transforms its keys using the provided function.

func Unique

func Unique[T comparable](s []T) (r []T)

Unique returns a new slice with only unique elements.

Types

This section is empty.

Jump to

Keyboard shortcuts

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