General

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 3 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepCopy

func DeepCopy(value any) any

func ExitFromProgram

func ExitFromProgram(err error)

ExitFromProgram is a utility function that handles program termination in case of an error. It prints the error message if the error is not nil, prompts the user to press enter to exit, and then terminates the program with a status code of 1.

Parameters:

  • err: The error that caused the program termination. If err is nil, no error message is printed.

Note: This function does not return. The program is terminated by calling os.Exit(1).

func FindMaximumValue

func FindMaximumValue[T any](comparisonFunc func(T, T) int, inputValues ...T) T

func FindMinimumValue

func FindMinimumValue[T any](comparisonFunc func(T, T) int, inputValues ...T) T

func MaxInt

func MaxInt(a, b int) int

MaxInt takes two integers as input and returns the larger value. If the values are equal, it returns the same value.

Example:

a := 5
b := 7
max := MaxInt(a, b)
fmt.Println(max) // Output: 7

func MinInt

func MinInt(a, b int) int

MinInt takes two integers as input and returns the smaller value. If the values are equal, it returns the same value.

Example:

a := 5
b := 7
min := MinInt(a, b)
fmt.Println(min) // Output: 5

func SplitIntoGroups

func SplitIntoGroups[T any](slice []T, n int) [][]T

SplitIntoGroups takes a slice of any type and an integer n as input. It splits the slice into n groups and returns a 2D slice where each inner slice represents a group. The elements are distributed based on their index in the original slice. If there are more elements than groups, the remaining elements are distributed to the groups in a round-robin fashion. If the number of groups (n) is less than or equal to 0, it panics with the message "The number of groups must be positive and non-zero". If the length of the slice is less than 2 or n is 1, it returns the original slice wrapped in a 2D slice.

Example:

slice := []int{1, 2, 3, 4, 5, 6}
n := 3
groups := SplitIntoGroups(slice, n)
fmt.Println(groups) // Output: [[1 4] [2 5] [3 6]]

func WaitForUserConfirmation

func WaitForUserConfirmation()

Types

This section is empty.

Jump to

Keyboard shortcuts

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