Documentation ¶
Index ¶
- func All[T any](s []T, f func(T) bool) bool
- func Any[T any](s []T, f func(T) bool) bool
- func Contains[T comparable](s []T, item T) bool
- func ContainsAny[T comparable](s []T, items ...T) bool
- func Deduplicate[T comparable](s []T) []T
- func Filter[T any](s []T, f func(T) bool) []T
- func Input(prompt string) string
- func IsDir(path string) bool
- func IsExecutable(path string) bool
- func IsFile(path string) bool
- func IsOwner(path string) bool
- func IsReadable(path string) bool
- func IsSymlink(path string) bool
- func IsWritable(path string) bool
- func Map[T, U any](s []T, f func(T) U) []U
- func Max[T Number](s []T) T
- func Min[T Number](s []T) T
- func Normalise(s string) string
- func PathExists(path string) bool
- func PrintBlue(s string)
- func PrintBold(s string)
- func PrintClear()
- func PrintClearLine()
- func PrintCyan(s string)
- func PrintGreen(s string)
- func PrintMagenta(s string)
- func PrintRed(s string)
- func PrintReset()
- func PrintUnderline(s string)
- func PrintWhite(s string)
- func PrintYellow(s string)
- func RandomChoice[T any](s []T) T
- func RandomInt(min, max int) int
- func RandomRange(min, max, length int) []int
- func RandomSequence(min, max, length int) chan int
- func RemoveIndex[T any](s []T, i int) []T
- func RemoveItems[T comparable](s []T, item T, max int) []T
- func ReverseSlice[T any](s []T) []T
- func ReverseString(s string) string
- func Shuffle[T any](slice []T)
- func SumSlice[T Number](s []T) T
- type Number
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All is a function that checks if all items in a slice satisfy a given condition and returns true or false accordingly.
func Any ¶
Any is a function that checks if any of the items in a slice satisfy a given condition and returns true or false accordingly.
func Contains ¶
func Contains[T comparable](s []T, item T) bool
Contains is a function that checks if a slice contains a given item and returns a boolean.
func ContainsAny ¶
func ContainsAny[T comparable](s []T, items ...T) bool
ContainsAny is a function that checks if a slice contains any of a given set of items and returns a boolean.
func Deduplicate ¶
func Deduplicate[T comparable](s []T) []T
Deduplicate removes duplicate elements from a slice and returns the result.
func Filter ¶
Filter is a function that filters a slice by a given condition and returns the resulting slice.
func IsExecutable ¶
IsExecutable is a function that returns true if the path exists and is executable.
func IsFile ¶
IsFile is a function that returns true if the path exists and is a regular file, i.e. not a directory, symlink, block device, etc.
func IsOwner ¶
IsOwner is a function that returns true if the path exists and is owned by the current user.
func IsReadable ¶
IsReadable is a function that returns true if the path exists and is readable.
func IsWritable ¶
IsWritable is a function that returns true if the path exists and is writable.
func Normalise ¶
Normalise is a function that returns a lowercase version of a string with leading and trailing whitespace removed.
func PathExists ¶
PathExists is a function that returns true if the path exists, whether it is a file, directory, symlink, or anything else.
func PrintClearLine ¶
func PrintClearLine()
PrintClearLine is a function that clears the current line.
func PrintMagenta ¶
func PrintMagenta(s string)
PrintMagenta is a function that prints a string in magenta.
func PrintReset ¶
func PrintReset()
PrintReset is a function that resets the terminal to its default state.
func PrintUnderline ¶
func PrintUnderline(s string)
PrintUnderline is a function that prints a string in underline.
func PrintYellow ¶
func PrintYellow(s string)
PrintYellow is a function that prints a string in yellow.
func RandomChoice ¶
func RandomChoice[T any](s []T) T
RandomChoice is a function that returns a random element from a slice.
func RandomInt ¶
RandomInt is a function that returns a random integer between min and max. To generate a large number of random integers, use RandomSequence instead.
func RandomRange ¶
RandomRange is a function that returns a slice of random integers between min and max.
func RandomSequence ¶
RandomSequence is a function that returns a channel of random integers between min and max. This method is more efficient than RandomRange, and can be used to generate an arbitrarily large number of random integers.
func RemoveIndex ¶
RemoveIndex is a function that removes an item by index from a slice and returns the resulting slice.
func RemoveItems ¶
func RemoveItems[T comparable](s []T, item T, max int) []T
RemoveItems is a function that removes items by value from a slice, up to a "max" times, and returns the resulting slice. If max is 0, all items are removed.
func ReverseString ¶
ReverseString is a function that reverses a string and returns the result.
Types ¶
type Number ¶
type Number interface { constraints.Integer | constraints.Float | constraints.Signed | constraints.Unsigned }
Number is an interface that represents any number type.