util

package
v0.0.0-...-71e909f Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[I constraints.Integer | constraints.Float](x I) I

Abs returns the absolute value of x. If x is negative, it returns -x.

func Debug

func Debug(message interface{}, args ...interface{})

Debug logs a debug message using the global logger function if it is set. The debug message can be any type. Additional arguments can be provided. If loggerFunc is nil, no action is taken.

func MapTuples

func MapTuples[A comparable, B any](t []tuple.Pair[A, B]) map[A]B

MapTuples creates a map from a slice of tuples.Pair. The keys are the values in V1 field of the pairs, and the values are the values in V2 field of the pairs. The function returns the created map.

func NormalizePath

func NormalizePath(path string) string

NormalizePath removes extraneous spaces, new lines, and carriage returns from the given path.

  • If the path starts with a tilde (~) character, it replaces the tilde with the user's home directory.
  • It then cleans the path to remove extra separators and dots.
  • Finally, it converts the path to its absolute form if possible.
  • If not, it returns the cleaned path.

func ProjectDir

func ProjectDir(elem ...string) string

func ProjectRootDir

func ProjectRootDir() string

func ReverseMap

func ReverseMap[K, V comparable](in map[K]V) map[V]K

ReverseMap reverses the key-value pairs of the input map and returns a new map.

func SetLoggerFunc

func SetLoggerFunc(l LoggerFunc)

SetLoggerFunc sets the global logger function to the provided LoggerFunc. The global logger function is used for logging messages throughout the library.

Types

type LoggerFunc

type LoggerFunc func(interface{}, ...interface{})

LoggerFunc represents a function that can be used for logging. It takes an interface{} argument which represents the log level or message, and a variadic ...interface{} argument for additional log data.

Jump to

Keyboard shortcuts

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