utils

package
v0.0.0-...-bd01111 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T constraints.Signed](x T) T

Abs returns the absolute value of x.

func Clamp

func Clamp[T constraints.Ordered](x, floor, ceil T) T

Clamp returns x clamped to the range [floor, ceil].

func ForkChannel

func ForkChannel[T any](in <-chan T) (out1, out2 <-chan T)

ForkChannel duplicates the input channel into two output channels.

func Max

func Max[T constraints.Ordered](a, b T) T

Max returns the larger of a and b.

func Min

func Min[T constraints.Ordered](a, b T) T

Min returns the smaller of a and b.

func Pow

func Pow[T constraints.Signed](x, y T) T

Pow returns x**y.

func ProbeChannel

func ProbeChannel[T any](in <-chan T, f func(v T)) (out <-chan T)

ProbeChannel duplicates the input channel into two output channels, applying a function to one of them and returning the other. Use this to e.g., log the data going through a channel.

func SafeAddUint16

func SafeAddUint16(a, b uint16) uint16

SafeAddInt16 adds a and b, returning math.MaxInt16 if the result would be greater than math.MaxInt16.

func SafeAddUint8

func SafeAddUint8(a, b uint8) uint8

SafeAddInt8 adds a and b, returning math.MaxInt8 if the result would be greater than math.MaxInt8.

func SafeSubUint16

func SafeSubUint16(a, b uint16) uint16

SafeSubInt16 subtracts b from a, returning 0 if the result would be less than 0.

func SafeSubUint8

func SafeSubUint8(a, b uint8) uint8

SafeSubInt8 subtracts b from a, returning 0 if the result would be less than 0.

func Sign

func Sign[T constraints.Signed](x T) T

Sign returns -1 if x < 0, 1 if x > 0, and 0 if x == 0.

Types

This section is empty.

Jump to

Keyboard shortcuts

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