utils

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bucketize added in v1.3.1

func Bucketize(value uint, buckets []uint) string

Bucketize will put the value of a metric into the correct bucket, and return the label for it. It is expected that the buckets are already sorted in increasing order and non-empty.

func Filter added in v1.9.0

func Filter[T any](s []T, predicate func(T) bool) iter.Seq[T]

Filter functions similar to other language list filter functions. It accepts a generic slice and a predicate function to apply to each element, returning an iterator sequence containing only the elements for which the predicate returned true.

Example filtering for even numbers:

iter := Filter([]int{1, 2, 3, 4, 5}, func(n int) bool { return n%2 == 0})
// To collect results: slices.Collect(iter) returns []int{2, 4}

func JitterDuration added in v1.9.0

func JitterDuration(baseDuration, maxJitter time.Duration) time.Duration

func LinearBuckets added in v1.4.1

func LinearBuckets(minValue, maxValue float64, count int) []float64

LinearBuckets returns an evenly distributed range of buckets in the closed interval [min...max]. The min and max count toward the bucket count since they are included in the range.

func Reduce added in v1.9.0

func Reduce[S ~[]E, E any, A any](s S, initializer A, f func(A, E) A) A

Reduce accepts a generic slice, an initializer value, and a function. It iterates over the slice applying the supplied function to the current accumulated value and each element in the slice, reducing the slice to a single value.

Example reducing to a sum:

Reduce([]int{1, 2, 3}, 0, func(accumulator int, currentValue int) int {
	return accumulator + currentValue
})

returns 6.

Types

This section is empty.

Directories

Path Synopsis
Package apimethod provides a type for the API grpc method names.
Package apimethod provides a type for the API grpc method names.

Jump to

Keyboard shortcuts

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