Documentation ¶
Index ¶
- func Clean(elem any)
- func Compare[T Comparable](a, b T) (int, bool)
- func CompareAny(a, b any) (int, bool)
- func CopyOf(elem any) any
- func EqualOf(a, b any) bool
- func ExtractFirsts[A any, B any](pairs []*Pair[A, B]) []A
- func ExtractSeconds[A any, B any](pairs []*Pair[A, B]) []B
- func GetOrdinalSuffix(number int) string
- func GoStringOf(elem any) string
- func HashCode(elem any) int
- func IsEmpty(elem any) bool
- func Max[T Comparable](a, b T) T
- func Min[T Comparable](a, b T) T
- func RunesOf(str any) []rune
- func StringOf(elem any) string
- func TypeOf(value any) string
- type Cleaner
- type Comparable
- type Copier
- type DoFunc
- type DualDoFunc
- type Enumer
- type Equaler
- type ErrorIfFunc
- type EvalManyFunc
- type EvalOneFunc
- type Hashable
- type MainFunc
- type Objecter
- type Pair
- type RoutineFunc
- type Runer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clean ¶
func Clean(elem any)
Clean removes all the elements from the data structure by calling the Clean method if the element implements the Cleaner interface.
Parameters:
- cleaner: The data structure to clean.
func Compare ¶
func Compare[T Comparable](a, b T) (int, bool)
Compare compares two values of the same type that implement the Comparable interface. If the values are equal, the function returns 0. If the first value is less than the second value, the function returns -1. If the first value is greater than the second value, the function returns 1.
Parameters:
- a: The first value to compare.
- b: The second value to compare.
Returns:
- int: -1 if a < b, 0 if a == b, 1 if a > b.
- bool: True if the values are comparable.
Behaviors:
- If the values are not comparable, the function returns false.
func CompareAny ¶
Compare compares two values of the same type that implement the Comparable interface. If the values are equal, the function returns 0. If the first value is less than the second value, the function returns -1. If the first value is greater than the second value, the function returns 1.
Parameters:
- a: The first value to compare.
- b: The second value to compare.
Returns:
- int: -1 if a < b, 0 if a == b, 1 if a > b.
- bool: True if the values are comparable.
Behaviors:
- If the values are not comparable, the function returns false.
func CopyOf ¶
CopyOf creates a copy of the element by either calling the Copy method if the element implements the Copier interface or returning the element as is.
Parameters:
- elem: The element to copy.
Returns:
- any: A copy of the element.
func EqualOf ¶
EqualOf compares two objects of the same type. If any of the objects implements the Equaler interface, the Equals method is called. Otherwise, the objects are compared using the == operator. However, a is always checked first.
Parameters:
- a: The first object to compare.
- b: The second object to compare.
Returns:
- bool: True if the objects are equal, false otherwise.
Behaviors:
- Nil objects are always considered different.
func ExtractFirsts ¶
ExtractFirsts extracts all the first elements from the given slice of pairs.
Parameters:
- pairs: The slice of pairs.
Returns:
- []A: The slice of first elements.
Behaviors:
- If the slice is empty, the function returns nil.
- If the slice contains only nil pairs, the function returns nil.
- This has the side effect of modifying the original slice when at least one nil pair is found. BEWARE!
func ExtractSeconds ¶
ExtractSeconds extracts all the second elements from the given slice of pairs.
Parameters:
- pairs: The slice of pairs.
Returns:
- []B: The slice of second elements.
Behaviors:
- If the slice is empty, the function returns nil.
- If the slice contains only nil pairs, the function returns nil.
- This has the side effect of modifying the original slice when at least one nil pair is found. BEWARE!
func GetOrdinalSuffix ¶
GetOrdinalSuffix returns the ordinal suffix for a given integer.
Parameters:
- number: The integer for which to get the ordinal suffix.
Returns:
- string: The ordinal suffix for the number.
For example, for the number 1, the function returns "1st"; for the number 2, it returns "2nd"; and so on.
func GoStringOf ¶
GoStringOf returns a string representation of the element.
Parameters:
- elem: The element to get the string representation of.
Returns:
- string: The string representation of the element.
Behaviors:
- If the element is nil, the function returns "nil".
- If the element implements the fmt.GoStringer interface, the function returns the result of the GoString method.
- If the element implements the fmt.Stringer interface, the function returns the result of the String method.
- If the element is a string, the function returns the string enclosed in double quotes.
- If the element is an error, the function returns the error message enclosed in double quotes.
- Otherwise, the function returns the result of the %#v format specifier.
func HashCode ¶
HashCode returns the hash code of an element. If the element implements the Hashable interface, the Hash method is called. Otherwise, the hash code is calculated using the default hash function.
Parameters:
- elem: The element to get the hash code from.
Returns:
- int: The hash code of the element.
func IsEmpty ¶
IsEmpty returns true if the element is empty.
Parameters:
- elem: The element to check.
Returns:
- bool: True if the element is empty, false otherwise.
func Max ¶
func Max[T Comparable](a, b T) T
Max is a function that takes two parameters, a and b, of any type T according to the uc.CompareOf function and returns the larger of the two values.
Parameters:
- a, b: The two values to compare.
Return:
- T: The larger of the two values.
func Min ¶
func Min[T Comparable](a, b T) T
Min is a function that takes two parameters, a and b, of any type T according to the uc.CompareOf function and returns the smaller of the two values.
Parameters:
- a, b: The two values to compare.
Return:
- T: The smaller of the two values.
func RunesOf ¶
RunesOf returns the runes of a string. If the string implements the Runer interface, the Runes method is called. Otherwise, the string is converted to a slice of runes.
Parameters:
- str: The string to get the runes from.
Returns:
- []rune: The runes of the string.
func StringOf ¶
StringOf converts any type to a string.
Parameters:
- elem: The element to convert to a string.
Returns:
- string: The string representation of the element.
Behaviors:
- String elements are returned as is.
- fmt.Stringer elements have their String method called.
- error elements have their Error method called.
- []byte and []rune elements are converted to strings.
- Other elements are converted to strings using fmt.Sprintf and the %v format.
Types ¶
type Cleaner ¶
type Cleaner interface {
// Clean removes all the elements from the data structure.
Clean()
}
Cleaner is an interface that provides a method to remove all the elements from a data structure.
type Comparable ¶
type Comparable interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~string }
Comparable is an interface that defines the behavior of a type that can be compared with other values of the same type using the < and > operators. The interface is implemented by the built-in types int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, and string.
type Copier ¶
type Copier interface { // Copy creates a copy of the element. // // Returns: // - Copier: The copy of the element. Copy() Copier }
Copier is an interface that provides a method to create a copy of an element.
type DoFunc ¶
type DoFunc[T any] func(T)
DoFunc is a generic type that represents a function that takes a value and does something with it.
Parameters:
- T: The type of the value.
type DualDoFunc ¶
DualDoFunc is a generic type that represents a function that takes two values and does something with them.
Parameters:
- T: The type of the first value.
- U: The type of the second value.
type Equaler ¶
type Equaler interface { // Equals returns true if the object is equal to the other object. // // Parameters: // - other: The other object to compare to. // // Returns: // - bool: True if the objects are equal, false otherwise. Equals(other Equaler) bool }
Equaler is an interface that defines a method to compare two objects of the same type for equality.
type ErrorIfFunc ¶
ErrorIfFunc is a function type that takes an element and returns an error if the element is invalid.
Parameters:
- elem: The element to check.
Returns:
- error: An error if the element is invalid.
type EvalManyFunc ¶
EvalManyFunc is a function that evaluates many elements.
Parameters:
- elem: The element to evaluate.
Returns:
- []R: The results of the evaluation.
- error: An error if the evaluation failed.
type EvalOneFunc ¶
EvalOneFunc is a function that evaluates one element.
Parameters:
- elem: The element to evaluate.
Returns:
- R: The result of the evaluation.
- error: An error if the evaluation failed.
type Hashable ¶
type Hashable interface { // Hash returns the hash code of the element. // // Returns: // - int: The hash code of the element. Hash() int }
Hashable is an interface that provides a method to get the hash code of an element.
type MainFunc ¶
type MainFunc func() error
MainFunc is a function type that takes no parameters and returns an error. It is used to represent things such as the main function of a program.
Returns:
- error: An error if the function failed.
type Objecter ¶
Objecter is an interface that defines the behavior of an object that can be copied, compared, and converted to a string.
type Pair ¶
Pair is a pair of values.
func NewPair ¶
NewPair creates a new pair.
Parameters:
- first: The first value.
- second: The second value.
Returns:
- Pair[A, B]: The new pair.
func RemoveNilPairs ¶
RemoveNilPairs removes all nil pairs from the given slice of pairs.
Parameters:
- pairs: The slice of pairs.
Returns:
- []*Pair[A, B]: The slice of pairs without nil pairs.
Behaviors:
- If the slice is empty, the function returns nil.
- This has the side effect of modifying the original slice when at least one nil pair is found. BEWARE!
func (*Pair[A, B]) Clean ¶
func (p *Pair[A, B]) Clean()
Clean cleans the pair by first calling the Clean() function on both the first and second values and then setting them to their zero values.
func (*Pair[A, B]) Copy ¶
Copy returns a shallow or deep copy of the pair according to the function CopyOf().
Returns:
- Copier: A shallow or deep copy of the pair.
type RoutineFunc ¶
type RoutineFunc func()
Routine is a function type used to represent a go routine.