Documentation ¶
Overview ¶
Package errors provides a custom error type for out-of-bound errors.
Package errors provides a custom error type for out-of-bound errors.
Index ¶
- func Assert(cond bool, msg string)
- func AssertErr(err error, format string, args ...any)
- func AssertF(cond bool, format string, args ...any)
- func AssertIfZero(elem any, msg string)
- func AssertParam(param string, cond bool, reason error)
- 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 Is[T error](err error) bool
- func IsDone(err error) bool
- func IsEmpty(elem any) bool
- func IsErrIgnorable(err error) bool
- func IsNoError(err error) bool
- func IsNotFound(err error) bool
- func LimitErrorMsg(err error, limit int) error
- func Max[T Comparable](a, b T) T
- func Min[T Comparable](a, b T) T
- func OrQuoteString(values []string, is_negative bool) string
- func OrString(values []string, is_negative bool) string
- func QuoteInt(value int) string
- func SliceCopy[T Copier](s []T) []T
- func SliceOf[T any](elem any) []T
- func StringOf(elem any) string
- func TrimEmpty(values []string) []string
- func TypeOf(value any) string
- type Builder
- type Comparable
- type Copier
- type DoFunc
- type DualDoFunc
- type DynamicIterator
- type Enumer
- type Equaler
- type ErrAfter
- type ErrAt
- type ErrBefore
- type ErrEmpty
- type ErrExhaustedIter
- type ErrGT
- type ErrGTE
- type ErrIgnorable
- type ErrInvalidCall
- type ErrInvalidParameter
- type ErrInvalidRune
- type ErrInvalidUsage
- type ErrInvalidValues
- type ErrLT
- type ErrLTE
- type ErrNilValue
- type ErrNoError
- type ErrNotFound
- type ErrOrSol
- type ErrOutOfBounds
- type ErrPanic
- type ErrPossibleError
- type ErrUnexpected
- type ErrUnexpectedError
- type ErrUnexpectedType
- type ErrVariableError
- type ErrWhile
- type ErrWhileAt
- type ErrorIfFunc
- type EvalManyFunc
- type EvalOneFunc
- type Iterable
- type Iterater
- type MainFunc
- type Objecter
- type Pair
- type ProceduralIterator
- type RoutineFunc
- type SimpleIterator
- type SliceIterator
- type Slicer
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assert ¶ added in v0.3.35
Assert panics if the condition is false.
Parameters:
- cond: The condition to check.
- msg: The message to show if the condition is false.
func AssertErr ¶ added in v0.3.38
AssertErr panics if the error is not nil.
Parameters:
- err: The error to check.
- format: The format of the message to show if the error is not nil.
- args: The arguments to format the message.
The format should be the function name and the args should be the parameters.
Example:
func MyFunc(param1 string, param2 int) { res, err := SomeFunc(param1, param2) AssertErr(err, "SomeFunc(%s, %d)", param1, param2) }
func AssertF ¶ added in v0.3.35
AssertF panics if the condition is false.
Parameters:
- cond: The condition to check.
- format: The format of the message to show if the condition is false.
- args: The arguments to format the message.
func AssertIfZero ¶ added in v0.3.35
AssertIfZero panics if the element is zero.
Parameters:
- elem: The element to check.
- msg: The message to show if the element is zero.
func AssertParam ¶ added in v0.3.35
AssertParam panics if the condition is false with a parameter name.
Parameters:
- param: The name of the parameter.
- cond: The condition to check.
- reason: The reason why the parameter is invalid.
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.
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.
func GetOrdinalSuffix ¶
GetOrdinalSuffix returns the ordinal suffix for a given integer.
Parameters:
- number: The integer for which to get the ordinal suffix. Negative numbers are treated as positive.
Returns:
- string: The ordinal suffix for the number.
Example:
- GetOrdinalSuffix(1) returns "1st"
- GetOrdinalSuffix(2) returns "2nd"
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 Is ¶ added in v0.3.34
Is is function that checks if an error is of type T.
Parameters:
- err: The error to check.
Returns:
- bool: true if the error is of type T, false otherwise (including if the error is nil).
func IsDone ¶ added in v0.3.37
IsDone checks if the iterator is exhausted.
Parameters:
- err: The error to check.
Returns:
- bool: True if the iterator is exhausted, false otherwise.
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 IsErrIgnorable ¶ added in v0.3.34
IsErrIgnorable checks if an error is an *ErrIgnorable or *ErrInvalidParameter error. If the error is nil, the function returns false.
Parameters:
- err: The error to check.
Returns:
- bool: True if the error is an *ErrIgnorable or *ErrInvalidParameter error, otherwise false.
func IsNoError ¶ added in v0.3.34
IsNoError checks if an error is a no error error or if it is nil.
Parameters:
- err: The error to check.
Returns:
- bool: True if the error is a no error error or if it is nil, otherwise false.
func IsNotFound ¶ added in v0.3.37
IsNotFound checks if the error is an ErrNotFound.
Parameters:
- err: The error to check.
Returns:
- bool: True if the error is an ErrNotFound, false otherwise.
func LimitErrorMsg ¶ added in v0.3.34
LimitErrorMsg limits the error message to a certain number of unwraps. It returns the top level error for allowing to print the error message with the limit of unwraps applied.
If the error is nil or the limit is less than 0, the function does nothing.
Parameters:
- err: The error to limit.
- limit: The limit of unwraps.
Returns:
- error: The top level error with the limit of unwraps applied.
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 OrQuoteString ¶ added in v0.3.37
OrQuoteString returns a string that represents a list of strings in a human-readable format. The strings are quoted and separated by commas and the last string is preceded by the word "or".
Empty strings are removed from the list according to the TrimEmpty function before being quoted.
Parameters:
- values: The list of strings to format.
- is_negative: Whether the list of strings is negative. (e.g. "a, b, nor c")
Returns:
- string: The formatted string.
Examples:
- OrQuoteString([]string{"a", "b", "c"}, false) => "\"a\", \"b\", or \"c\""
func OrString ¶ added in v0.3.37
OrString returns a string that represents a list of strings in a human-readable format. The strings are separated by commas and the last string is preceded by the word "or".
Empty strings are removed from the list according to the TrimEmpty function.
Parameters:
- values: The list of strings to format.
- is_negative: Whether the list of strings is negative. (e.g. "a, b, nor c")
Returns:
- string: The formatted string.
Examples:
- OrString([]string{"a", "b", "c"}) => "a, b, or c"
func QuoteInt ¶ added in v0.3.35
QuoteInt returns a quoted string of an integer prefixed and suffixed with square brackets.
Parameters:
- value: The integer to quote.
Returns:
- string: The quoted integer.
func SliceCopy ¶ added in v0.3.31
func SliceCopy[T Copier](s []T) []T
SliceCopy creates a copy of a slice of elements by calling the Copy method of each element if the element implements the Copier interface.
Whether or not the copy is a shallow or deep copy depends on the implementation of the Copy method of the element.
Parameters:
- s: The slice of elements to copy.
Returns:
- []T: The copy of the slice of elements.
func SliceOf ¶ added in v0.3.34
SliceOf converts any type to a slice of elements of the same type.
Parameters:
- elem: The element to convert to a slice.
Returns:
- []T: The slice representation of the element.
Behaviors:
- Nil elements are converted to nil slices.
- Slice elements are returned as is.
- Slicer elements have their Slice method called.
- Other elements are converted to slices containing a single element.
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 Builder ¶ added in v0.3.34
type Builder[T any] struct { // contains filtered or unexported fields }
Builder is a struct that allows building iterators over a collection of elements.
func (*Builder[T]) Add ¶ added in v0.3.34
func (b *Builder[T]) Add(element T)
Add is a method of the Builder type that appends an element to the buffer.
Parameters:
- element: The element to append to the buffer.
func (*Builder[T]) AddMany ¶ added in v0.3.34
func (b *Builder[T]) AddMany(elements []T)
AddMany is a method of the Builder type that appends multiple elements to the buffer.
Parameters:
- elements: The elements to append to the buffer.
func (*Builder[T]) Build ¶ added in v0.3.34
func (b *Builder[T]) Build() *SimpleIterator[T]
Build creates a new iterator over the buffer of elements.
It clears the buffer after creating the iterator.
Returns:
- *SimpleIterator[T]: The new iterator.
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 DynamicIterator ¶ added in v0.3.34
type DynamicIterator[E, T any] struct { // contains filtered or unexported fields }
DynamicIterator is a struct that allows iterating over a collection of iterators of type Iterater[T].
func NewDynamicIterator ¶ added in v0.3.34
func NewDynamicIterator[E, T any](source Iterater[E], f func(E) Iterater[T]) *DynamicIterator[E, T]
IteratorFromIterator creates a new iterator over a collection of iterators of type Iterater[T]. It uses the input iterator to iterate over the collection of iterators and return the elements from each iterator in turn.
Parameters:
- source: The iterator over the collection of iterators to iterate over.
- f: The transition function that takes an element of type E and returns an iterator.
Return:
- *DynamicIterator[E, T]: The new iterator. Nil if f or source is nil.
func (*DynamicIterator[E, T]) Consume ¶ added in v0.3.34
func (di *DynamicIterator[E, T]) Consume() (T, error)
Consume implements the Iterater interface.
func (*DynamicIterator[E, T]) Restart ¶ added in v0.3.34
func (di *DynamicIterator[E, T]) Restart()
Restart implements the Iterater interface.
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 ErrAfter ¶ added in v0.3.34
type ErrAfter struct { // After is the element that was processed before the error occurred. After string // Reason is the reason for the error. Reason error }
ErrAfter is an error that is returned when something goes wrong after a certain element in a stream of data.
func NewErrAfter ¶ added in v0.3.34
NewErrAfter creates a new ErrAfter error.
Parameters:
- after: The element that was processed before the error occurred.
- reason: The reason for the error.
Returns:
- *ErrAfter: A pointer to the new ErrAfter error.
func (*ErrAfter) ChangeReason ¶ added in v0.3.34
ChangeReason implements the Unwrapper interface.
type ErrAt ¶ added in v0.3.34
type ErrAt struct { // Index is the index where the error occurred. Index int // Name is the name of the index. Name string // Reason is the reason for the error. Reason error }
ErrAt represents an error that occurs at a specific index.
func NewErrAt ¶ added in v0.3.34
NewErrAt creates a new ErrAt error.
Parameters:
- index: The index where the error occurred.
- name: The name of the index.
- reason: The reason for the error.
Returns:
- *ErrAt: A pointer to the newly created ErrAt.
func (*ErrAt) ChangeReason ¶ added in v0.3.34
ChangeReason implements the Unwrapper interface.
type ErrBefore ¶ added in v0.3.34
type ErrBefore struct { // Before is the element that was processed before the error occurred. Before string // Reason is the reason for the error. Reason error }
ErrBefore is an error that is returned when something goes wrong before a certain element in a stream of data.
func NewErrBefore ¶ added in v0.3.34
NewErrBefore creates a new ErrBefore error.
Parameters:
- before: The element that was processed before the error occurred.
- reason: The reason for the error.
Returns:
- *ErrBefore: A pointer to the new ErrBefore error.
func (*ErrBefore) ChangeReason ¶ added in v0.3.34
ChangeReason implements the Unwrapper interface.
type ErrEmpty ¶ added in v0.3.34
type ErrEmpty[T any] struct { // Value is the value that caused the error. Value T }
ErrEmpty represents an error when a value is empty.
func NewErrEmpty ¶ added in v0.3.34
NewErrEmpty creates a new ErrEmpty error.
Parameters:
- value: The value that caused the error.
Returns:
- *ErrEmpty: A pointer to the newly created ErrEmpty.
type ErrExhaustedIter ¶ added in v0.3.34
type ErrExhaustedIter struct{}
ErrExhaustedIter is an error type that is returned when an iterator is exhausted (i.e., there are no more elements to consume).
func NewErrExhaustedIter ¶ added in v0.3.34
func NewErrExhaustedIter() *ErrExhaustedIter
NewErrExhaustedIter creates a new ErrExhaustedIter error.
Returns:
- *ErrExhaustedIter: A pointer to the new error.
func (*ErrExhaustedIter) Error ¶ added in v0.3.34
func (e *ErrExhaustedIter) Error() string
Error implements the error interface.
Message: "iterator is exhausted"
type ErrGT ¶ added in v0.3.34
type ErrGT struct { // Value is the value that caused the error. Value int }
ErrGT represents an error when a value is less than or equal to a specified value.
type ErrGTE ¶ added in v0.3.34
type ErrGTE struct { // Value is the value that caused the error. Value int }
ErrGTE represents an error when a value is less than a specified value.
type ErrIgnorable ¶ added in v0.3.34
type ErrIgnorable struct { // Err is the error that can be ignored. Err error }
ErrIgnorable represents an error that can be ignored. Useful for indicating that an error is ignorable.
func NewErrIgnorable ¶ added in v0.3.34
func NewErrIgnorable(err error) *ErrIgnorable
NewErrIgnorable creates a new ErrIgnorable error.
Parameters:
- err: The error that can be ignored.
Returns:
- *ErrIgnorable: A pointer to the newly created ErrIgnorable.
func (*ErrIgnorable) ChangeReason ¶ added in v0.3.34
func (e *ErrIgnorable) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrIgnorable) Error ¶ added in v0.3.34
func (e *ErrIgnorable) Error() string
Error implements the Unwrapper interface.
Message: "ignorable error" if the reason is nil, otherwise the error message.
func (*ErrIgnorable) Unwrap ¶ added in v0.3.34
func (e *ErrIgnorable) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrInvalidCall ¶ added in v0.3.34
type ErrInvalidCall struct { // FnName is the name of the function. FnName string // Signature is the Signature of the function. Signature reflect.Type // Reason is the Reason for the failure. Reason error }
ErrInvalidCall represents an error that occurs when a function is not called correctly.
func NewErrInvalidCall ¶ added in v0.3.34
func NewErrInvalidCall(functionName string, function any, reason error) *ErrInvalidCall
NewErrInvalidCall creates a new ErrInvalidCall.
Parameters:
- functionName: The name of the function.
- function: The function that failed.
- reason: The reason for the failure.
Returns:
- *ErrInvalidCall: A pointer to the new ErrInvalidCall.
func (*ErrInvalidCall) ChangeReason ¶ added in v0.3.34
func (e *ErrInvalidCall) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrInvalidCall) Error ¶ added in v0.3.34
func (e *ErrInvalidCall) Error() string
Error implements the Unwrapper interface.
Message: "call to {function}({signature}) failed: {reason}".
However, if the reason is nil, the message is "call to {function}({signature}) failed" instead.
func (*ErrInvalidCall) Unwrap ¶ added in v0.3.34
func (e *ErrInvalidCall) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrInvalidParameter ¶ added in v0.3.34
type ErrInvalidParameter struct { // Parameter is the name of the Parameter. Parameter string // Reason is the Reason for the invalidity of the parameter. Reason error }
ErrInvalidParameter represents an error when a parameter is invalid.
func NewErrInvalidParameter ¶ added in v0.3.34
func NewErrInvalidParameter(parameter string, reason error) *ErrInvalidParameter
NewErrInvalidParameter creates a new ErrInvalidParameter error.
Parameters:
- parameter: The name of the parameter.
- reason: The reason for the invalidity.
Returns:
- *ErrInvalidParameter: A pointer to the newly created ErrInvalidParameter.
func NewErrNilParameter ¶ added in v0.3.34
func NewErrNilParameter(parameter string) *ErrInvalidParameter
ErrNilParameter represents an error when a parameter is nil. This is a shorthand for NewErrInvalidParameter(parameter, NewErrNilValue()).
Parameters:
- parameter: The name of the parameter.
Returns:
- *ErrInvalidParameter: A pointer to the newly created ErrInvalidParameter.
func (*ErrInvalidParameter) ChangeReason ¶ added in v0.3.34
func (e *ErrInvalidParameter) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrInvalidParameter) Error ¶ added in v0.3.34
func (e *ErrInvalidParameter) Error() string
Error implements the Unwrapper interface.
Message: "parameter ({parameter}) is invalid: {reason}".
However, if the reason is nil, the message is "parameter ({parameter}) is invalid" instead.
func (*ErrInvalidParameter) Unwrap ¶ added in v0.3.34
func (e *ErrInvalidParameter) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrInvalidRune ¶ added in v0.3.34
type ErrInvalidRune struct { // Reason is the reason for the invalidity of the rune. Reason error }
ErrInvalidRune represents an error when an invalid rune is encountered.
func NewErrInvalidRune ¶ added in v0.3.34
func NewErrInvalidRune(reason error) *ErrInvalidRune
NewErrInvalidRune creates a new ErrInvalidRuneAt error.
Parameters:
- reason: The reason for the invalidity of the rune.
Returns:
- *ErrInvalidRune: A pointer to the newly created ErrInvalidRune.
func (*ErrInvalidRune) ChangeReason ¶ added in v0.3.34
func (e *ErrInvalidRune) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrInvalidRune) Error ¶ added in v0.3.34
func (e *ErrInvalidRune) Error() string
Error implements the Unwrapper interface.
Message: "invalid rune: {reason}".
However, if the reason is nil, the message is "rune is invalid" instead.
func (*ErrInvalidRune) Unwrap ¶ added in v0.3.34
func (e *ErrInvalidRune) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrInvalidUsage ¶ added in v0.3.34
type ErrInvalidUsage struct { // Reason is the reason for the invalid usage. Reason error // Usage is the usage of the function. Usage string }
ErrInvalidUsage represents an error that occurs when a function is used incorrectly.
func NewErrInvalidUsage ¶ added in v0.3.34
func NewErrInvalidUsage(reason error, usage string) *ErrInvalidUsage
NewErrInvalidUsage creates a new ErrInvalidUsage error.
Parameters:
- reason: The reason for the invalid usage.
- usage: The usage of the function.
Returns:
- *ErrInvalidUsage: A pointer to the new ErrInvalidUsage error.
func (*ErrInvalidUsage) ChangeReason ¶ added in v0.3.34
func (e *ErrInvalidUsage) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrInvalidUsage) Error ¶ added in v0.3.34
func (e *ErrInvalidUsage) Error() string
Error is a method of the Unwrapper interface.
Message: "{reason}. {usage}".
However, if the reason is nil, the message is "invalid usage. {usage}" instead.
If the usage is empty, no usage is added to the message.
func (*ErrInvalidUsage) Unwrap ¶ added in v0.3.34
func (e *ErrInvalidUsage) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrInvalidValues ¶ added in v0.3.34
type ErrInvalidValues[T comparable] struct { // Values is the list of invalid values. Values []T }
ErrInvalidValues represents an error when a value is in a list of invalid values.
func NewErrInvalidValues ¶ added in v0.3.34
func NewErrInvalidValues[T comparable](values []T) *ErrInvalidValues[T]
NewErrInvalidValues creates a new ErrInvalidValues error.
Parameters:
- values: The list of invalid values.
Returns:
- *ErrInvalidValues: A pointer to the newly created ErrInvalidValues.
func NewErrUnexpectedValue ¶ added in v0.3.34
func NewErrUnexpectedValue[T comparable](value T) *ErrInvalidValues[T]
NewErrUnexpectedValue is a function that creates a new ErrInvalidValues error.
Parameters:
- value: The value that was unexpected.
Returns:
- *ErrInvalidValues: A pointer to the newly created ErrInvalidValues.
func (*ErrInvalidValues[T]) Error ¶ added in v0.3.34
func (e *ErrInvalidValues[T]) Error() string
Error implements the error interface.
Message: "value must not be <value 0>, <value 1>, <value 2>, ..., or <value n>"
If no values are provided, the message is "value is invalid".
type ErrLT ¶ added in v0.3.34
type ErrLT struct { // Value is the value that caused the error. Value int }
ErrLT represents an error when a value is greater than or equal to a specified value.
type ErrLTE ¶ added in v0.3.34
type ErrLTE struct { // Value is the value that caused the error. Value int }
ErrLTE represents an error when a value is greater than a specified value.
type ErrNilValue ¶ added in v0.3.34
type ErrNilValue struct{}
ErrNilValue represents an error when a value is nil.
func NewErrNilValue ¶ added in v0.3.34
func NewErrNilValue() *ErrNilValue
NewErrNilValue creates a new ErrNilValue error.
Returns:
- *ErrNilValue: The new ErrNilValue error.
func (*ErrNilValue) Error ¶ added in v0.3.34
func (e *ErrNilValue) Error() string
Error implements the error interface.
Message: "pointer must not be nil"
type ErrNoError ¶ added in v0.3.34
type ErrNoError struct { // Err is the reason for the no error error. Err error }
ErrNoError represents an error when no error occurs.
func NewErrNoError ¶ added in v0.3.34
func NewErrNoError(err error) *ErrNoError
NewErrNoError creates a new ErrNoError error.
Parameters:
- err: The reason for the no error error.
Returns:
- *ErrNoError: A pointer to the newly created ErrNoError.
func (*ErrNoError) ChangeReason ¶ added in v0.3.34
func (e *ErrNoError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrNoError) Error ¶ added in v0.3.34
func (e *ErrNoError) Error() string
Error implements the Unwrapper interface.
Message: "no error" if the reason is nil, otherwise the error message.
func (*ErrNoError) Unwrap ¶ added in v0.3.34
func (e *ErrNoError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrNotFound ¶ added in v0.3.37
type ErrNotFound struct{}
ErrNotFound is an error type that is returned when a value is not found.
func NewErrNotFound ¶ added in v0.3.37
func NewErrNotFound() *ErrNotFound
NewErrNotFound creates a new ErrNotFound error.
Returns:
- *ErrNotFound: A pointer to the new error.
func (*ErrNotFound) Error ¶ added in v0.3.37
func (e *ErrNotFound) Error() string
Error implements the error interface.
Message: "not found"
type ErrOrSol ¶ added in v0.3.34
type ErrOrSol[T any] struct { // contains filtered or unexported fields }
ErrOrSol is a struct that holds a list of errors and a list of solutions.
func (*ErrOrSol[T]) AddAny ¶ added in v0.3.34
AddAny adds an element to the list of errors or solutions if the level is greater or equal to the current level.
Parameters:
- elem: The element to add.
- level: The level of the element.
Behaviors:
- If an error has been added with a level greater than the current level, the error list is reset and the new level is updated.
- If a solution has been added with a level greater than the current level, the solution list is reset and the new level is updated.
func (*ErrOrSol[T]) AddErr ¶ added in v0.3.34
AddErr adds an error to the list of errors if the level is greater or equal to the current level.
Parameters:
- err: The error to add.
- level: The level of the error.
Behaviors:
- If an error has been added with a level greater than the current level, the error list is reset and the new level is updated.
- If the error is nil, the ignoreErr flag is set to true and the error list is reset.
func (*ErrOrSol[T]) AddSol ¶ added in v0.3.34
AddSol adds a solution to the list of solutions if the level is greater or equal to the current level.
Parameters:
- sol: The solution to add.
- level: The level of the solution.
Behaviors:
- If a solution has been added with a level greater than the current level, the solution list is reset and the new level is updated.
- This function sets the ignoreErr flag to true and resets the error list.
func (*ErrOrSol[T]) GetErrors ¶ added in v0.3.34
GetErrors returns the list of errors.
Returns:
- []error: The list of errors.
func (*ErrOrSol[T]) GetSolutions ¶ added in v0.3.34
func (e *ErrOrSol[T]) GetSolutions() []T
GetSolutions returns the list of solutions.
Returns:
- []T: The list of solutions.
type ErrOutOfBounds ¶ added in v0.3.34
type ErrOutOfBounds struct {
// LowerBound and UpperBound are the lower and upper bounds of the range,
// respectively.
LowerBound, UpperBound int
// LowerInclusive and UpperInclusive are flags indicating whether the lower
// and upper bounds are inclusive, respectively.
LowerInclusive, UpperInclusive bool
// Value is the value that caused the error.
Value int
}
ErrOutOfBounds represents an error when a value is out of a specified range.
func NewErrOutOfBounds ¶ added in v0.3.34
func NewErrOutOfBounds(value int, lowerBound, upperBound int) *ErrOutOfBounds
NewOutOfBounds creates a new ErrOutOfBound error. By default, the lower bound is inclusive and the upper bound is exclusive.
Parameters:
- lowerBound, upperbound: The lower and upper bounds of the range, respectively.
- value: The value that caused the error.
Returns:
- *ErrOutOfBounds: A pointer to the newly created ErrOutOfBound.
func (*ErrOutOfBounds) Error ¶ added in v0.3.34
func (e *ErrOutOfBounds) Error() string
Error implements the error interface.
Message: "value (value) not in range <lowerBound, upperBound>"
If the lower bound is inclusive, the message uses square brackets. If the upper bound is inclusive, the message uses square brackets. Otherwise, the message uses parentheses.
func (*ErrOutOfBounds) WithLowerBound ¶ added in v0.3.34
func (e *ErrOutOfBounds) WithLowerBound(isInclusive bool) *ErrOutOfBounds
WithLowerBound sets the inclusivity of the lower bound.
Parameters:
- isInclusive: A boolean indicating whether the lower bound is inclusive.
Returns:
- *ErrOutOfBound: The error instance for chaining.
func (*ErrOutOfBounds) WithUpperBound ¶ added in v0.3.34
func (e *ErrOutOfBounds) WithUpperBound(isInclusive bool) *ErrOutOfBounds
WithUpperBound sets the inclusivity of the upper bound.
Parameters:
- isInclusive: A boolean indicating whether the upper bound is inclusive.
Returns:
- *ErrOutOfBound: The error instance for chaining.
type ErrPanic ¶ added in v0.3.34
type ErrPanic struct { // Value is the value that caused the panic. Value any }
ErrPanic represents an error when a panic occurs.
func NewErrPanic ¶ added in v0.3.34
NewErrPanic creates a new ErrPanic error.
Parameters:
- value: The value that caused the panic.
Returns:
- *ErrPanic: A pointer to the newly created ErrPanic.
type ErrPossibleError ¶ added in v0.3.34
type ErrPossibleError struct { // Reason is the reason for the possible error. Reason error // Possible is the possible error. Possible error }
ErrPossibleError represents an error that occurs when a possible error is encountered.
func NewErrPossibleError ¶ added in v0.3.34
func NewErrPossibleError(reason error, possible error) *ErrPossibleError
NewErrPossibleError creates a new ErrPossibleError error.
Parameters:
- reason: The reason for the possible error.
- possible: The possible error.
Returns:
- *ErrPossibleError: A pointer to the new ErrPossibleError error.
func (*ErrPossibleError) ChangeReason ¶ added in v0.3.34
func (e *ErrPossibleError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrPossibleError) Error ¶ added in v0.3.34
func (e *ErrPossibleError) Error() string
Error implements the Unwrapper interface.
Message: "{reason}. It is possible that {possible}".
However, if the reason is nil, the message is "no error occurred. It is possible that {possible}" instead.
If the possible error is nil, the "It is possible that {possible}" part is omitted.
func (*ErrPossibleError) Unwrap ¶ added in v0.3.34
func (e *ErrPossibleError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrUnexpected ¶ added in v0.3.34
type ErrUnexpected struct { // Expected is the list of expected values. Expected []string // Actual is the actual value encountered. Actual string }
ErrUnexpected represents an error that occurs when an unexpected value is encountered.
func NewErrUnexpected ¶ added in v0.3.34
func NewErrUnexpected(got string, expected ...string) *ErrUnexpected
NewErrUnexpected creates a new ErrUnexpected error.
Parameters:
- got: The actual value encountered.
- expected: The list of expected values.
Returns:
- *ErrUnexpected: A pointer to the newly created ErrUnexpected.
func (*ErrUnexpected) Error ¶ added in v0.3.34
func (e *ErrUnexpected) Error() string
Error implements the error interface.
Message: "expected <value 0>, <value 1>, <value 2>, ..., or <value n>, got <actual> instead"
type ErrUnexpectedError ¶ added in v0.3.34
type ErrUnexpectedError struct { // Reason is the reason for the unexpected error. Reason error }
ErrUnexpectedError represents an error that occurs unexpectedly.
func NewErrUnexpectedError ¶ added in v0.3.34
func NewErrUnexpectedError(reason error) *ErrUnexpectedError
NewErrUnexpectedError creates a new ErrUnexpectedError error.
Parameters:
- reason: The reason for the unexpected error.
Returns:
- *ErrUnexpectedError: A pointer to the new ErrUnexpectedError error.
func (*ErrUnexpectedError) ChangeReason ¶ added in v0.3.34
func (e *ErrUnexpectedError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrUnexpectedError) Error ¶ added in v0.3.34
func (e *ErrUnexpectedError) Error() string
Error implements the Unwrapper interface.
Message: "unexpected error: {reason}".
However, if the reason is nil, the message is "unexpected error" instead.
func (*ErrUnexpectedError) Unwrap ¶ added in v0.3.34
func (e *ErrUnexpectedError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrUnexpectedType ¶ added in v0.3.34
type ErrUnexpectedType[T any] struct { // Elem is the element that caused the error. Elem T // Kind is the category of the type that was expected. Kind string }
ErrUnexpectedType represents an error when a value has an invalid type.
func NewErrUnexpectedType ¶ added in v0.3.34
func NewErrUnexpectedType[T any](kind string, elem T) *ErrUnexpectedType[T]
NewErrUnexpectedType creates a new ErrUnexpectedType error.
Parameters:
- typeName: The name of the type that was expected.
- elem: The element that caused the error.
Returns:
- *ErrUnexpectedType: A pointer to the newly created ErrUnexpectedType.
func (*ErrUnexpectedType[T]) Error ¶ added in v0.3.34
func (e *ErrUnexpectedType[T]) Error() string
Error implements the error interface.
Message: "type <type> is not a valid <kind> type"
type ErrVariableError ¶ added in v0.3.34
type ErrVariableError struct { // Variable is the name of the variable that caused the error. Variable string // Reason is the reason for the variable error. Reason error }
ErrVariableError represents an error that occurs when a variable is invalid.
func NewErrVariableError ¶ added in v0.3.34
func NewErrVariableError(variable string, reason error) *ErrVariableError
NewErrVariableError creates a new ErrVariableError error.
Parameters:
- variable: The name of the variable that caused the error.
- reason: The reason for the variable error.
Returns:
- *ErrVariableError: A pointer to the new ErrVariableError error.
func (*ErrVariableError) ChangeReason ¶ added in v0.3.34
func (e *ErrVariableError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrVariableError) Error ¶ added in v0.3.34
func (e *ErrVariableError) Error() string
Error implements the Unwrapper interface.
Message: "variable ({variable}) error: {reason}".
However, if the reason is nil, the message is "variable ({variable}) error" instead.
func (*ErrVariableError) Unwrap ¶ added in v0.3.34
func (e *ErrVariableError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrWhile ¶ added in v0.3.34
type ErrWhile struct { // Operation is the operation that was being performed. Operation string // Reason is the reason for the error. Reason error }
ErrWhile represents an error that occurs while performing an operation.
func NewErrWhile ¶ added in v0.3.34
NewErrWhile creates a new ErrWhile error.
Parameters:
- operation: The operation that was being performed.
- reason: The reason for the error.
Returns:
- *ErrWhile: A pointer to the newly created ErrWhile.
func (*ErrWhile) ChangeReason ¶ added in v0.3.34
ChangeReason implements the Unwrapper interface.
type ErrWhileAt ¶ added in v0.3.34
type ErrWhileAt struct { // Index is the index where the error occurred. Index int // Element is the element where the index is pointing to. Element string // Operation is the operation that was being performed. Operation string // Reason is the reason for the error. Reason error }
ErrWhileAt represents an error that occurs while performing an operation at a specific index.
func NewErrWhileAt ¶ added in v0.3.34
func NewErrWhileAt(operation string, index int, elem string, reason error) *ErrWhileAt
NewErrWhileAt creates a new ErrWhileAt error.
Parameters:
- operation: The operation that was being performed.
- index: The index where the error occurred.
- elem: The element where the index is pointing to.
- reason: The reason for the error.
Returns:
- *ErrWhileAt: A pointer to the newly created ErrWhileAt.
func (*ErrWhileAt) ChangeReason ¶ added in v0.3.34
func (e *ErrWhileAt) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrWhileAt) Error ¶ added in v0.3.34
func (e *ErrWhileAt) Error() string
Error implements the Unwrapper interface.
Message: "an error occurred while {operation} at index {index} {element}: {reason}"
However, if the reason is nil, the message is "an error occurred while {operation} at index {index} {element}" instead.
func (*ErrWhileAt) Unwrap ¶ added in v0.3.34
func (e *ErrWhileAt) Unwrap() error
Unwrap implements the Unwrapper interface.
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 Iterable ¶ added in v0.3.34
type Iterable[T any] interface { // Iterator returns an iterator over the collection of elements. // // Returns: // - Iterater[T]: An iterator over the collection of elements. Iterator() Iterater[T] }
Iterable is an interface that defines a method to get an iterator over a collection of elements of type T. It is implemented by data structures that can be iterated over.
type Iterater ¶ added in v0.3.34
type Iterater[T any] interface { // Consume advances the iterator to the next element in the // collection and returns the current element. // // Returns: // - T: The current element in the collection. // - error: An error if the iterator is exhausted or if an error occurred // while consuming the element. Consume() (T, error) // Restart resets the iterator to the beginning of the // collection. Restart() }
Iterater is an interface that defines methods for an iterator over a collection of elements of type T.
func IteratorOf ¶ added in v0.3.34
IteratorOf converts any type to an iterator over elements of the same type.
Parameters:
- elem: The element to convert to an iterator.
Returns:
- Iterater[T]: The iterator over the element.
Behaviors:
- IF elem is nil, an empty iterator is returned.
- IF elem -implements-> Iterater[T], the element is returned as is.
- IF elem -implements-> Iterable[T], the element's Iterator method is called.
- IF elem -implements-> []T, a new iterator over the slice is created.
- ELSE, a new iterator over a single-element collection is created.
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 ¶
type Pair[A, B any] struct { // The first value. First A // The second value. Second B }
Pair is a pair of values.
type ProceduralIterator ¶ added in v0.3.34
ProceduralIterator is a struct that allows iterating over a collection of iterators of type Iterater[T].
func NewProceduralIterator ¶ added in v0.3.34
func NewProceduralIterator[E Iterable[T], T any](source Iterater[E]) *ProceduralIterator[E, T]
IteratorFromIterator creates a new iterator over a collection of iterators of type Iterater[T]. It uses the input iterator to iterate over the collection of iterators and return the elements from each iterator in turn.
Parameters:
- source: The iterator over the collection of iterators to iterate over.
Return:
- *ProceduralIterator[E, T]: The new iterator over the collection of elements. Nil if source is nil.
func (*ProceduralIterator[E, T]) Consume ¶ added in v0.3.34
func (pi *ProceduralIterator[E, T]) Consume() (T, error)
Consume implements the Iterater interface.
func (*ProceduralIterator[E, T]) Restart ¶ added in v0.3.34
func (pi *ProceduralIterator[E, T]) Restart()
Restart implements the Iterater interface.
type RoutineFunc ¶
type RoutineFunc func()
Routine is a function type used to represent a go routine.
type SimpleIterator ¶ added in v0.3.34
type SimpleIterator[T any] struct { // contains filtered or unexported fields }
SimpleIterator is a struct that allows iterating over a slice of elements of any type.
func NewSimpleIterator ¶ added in v0.3.34
func NewSimpleIterator[T any](values []T) *SimpleIterator[T]
NewSimpleIterator creates a new iterator over a slice of elements of type T.
Parameters:
- values: The slice of elements to iterate over.
Return:
- *SimpleIterator[T]: A new iterator over the given slice of elements.
Behaviors:
- If values is nil, the iterator is initialized with an empty slice.
- Modifications to the slice of elements after creating the iterator will affect the values seen by the iterator.
func (*SimpleIterator[T]) Consume ¶ added in v0.3.34
func (iter *SimpleIterator[T]) Consume() (T, error)
Consume implements the Iterater interface.
func (*SimpleIterator[T]) Restart ¶ added in v0.3.34
func (iter *SimpleIterator[T]) Restart()
Restart implements the Iterater interface.
type SliceIterator ¶ added in v0.3.37
type SliceIterator[T any] struct { // contains filtered or unexported fields }
SliceIterator is a struct that allows iterating over a collection of iterators of type Iterater[T].
func NewSliceIterator ¶ added in v0.3.37
func NewSliceIterator[T any](source Iterater[[]T]) *SliceIterator[T]
IteratorFromIterator creates a new iterator over a collection of iterators of type Iterater[T]. It uses the input iterator to iterate over the collection of iterators and return the elements from each iterator in turn.
Parameters:
- source: The iterator over the collection of iterators to iterate over.
Return:
- *SliceIterator[T]: The new iterator over the collection of elements. Nil if source is nil.
func (*SliceIterator[T]) Consume ¶ added in v0.3.37
func (pi *SliceIterator[T]) Consume() (T, error)
Consume implements the Iterater interface.
func (*SliceIterator[T]) Restart ¶ added in v0.3.37
func (pi *SliceIterator[T]) Restart()
Restart implements the Iterater interface.
type Slicer ¶ added in v0.3.34
type Slicer[T any] interface { // Slice returns a slice containing all the elements in the data structure. // // Returns: // - []T: A slice containing all the elements in the data structure. Slice() []T Iterable[T] }
Slicer is an interface that provides a method to convert a data structure to a slice.
type Unwrapper ¶ added in v0.3.34
type Unwrapper interface { // Unwrap returns the error that this error wraps. // // Returns: // - error: The error that this error wraps. Unwrap() error // ChangeReason changes the reason of the error. // // Parameters: // - reason: The new reason of the error. ChangeReason(reason error) error }
Unwrapper is an interface that defines a method to unwrap an error.