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 AssertConv[T any](elem any, var_name string) T
- func AssertDerefNil[T any](elem *T, param_name string) T
- func AssertErr(err error, format string, args ...any)
- func AssertF(cond bool, format string, args ...any)
- func AssertNil[T any](elem *T, param_name string)
- func AssertOk(ok bool, format string, args ...any)
- func AssertParam(param string, cond bool, reason error)
- func AssertType[T any](elem any, allow_nil bool, var_name string)
- func CopyOf(elem any) any
- func EqualOf(a, b any) bool
- func GetOrdinalSuffix(number int) string
- func Is[T error](err error) bool
- func IsDone(err error) 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 cmp.Ordered](a, b T) T
- func Min[T cmp.Ordered](a, b T) T
- func SliceCopy[T Copier](s []T) []T
- func SliceOf[T any](elem any) []T
- type Builder
- 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 ErrInvalidParameter
- type ErrInvalidRune
- type ErrInvalidUsage
- type ErrLT
- type ErrLTE
- type ErrNilValue
- type ErrNoError
- type ErrNotFound
- type ErrOrSol
- type ErrOutOfBounds
- type ErrPanic
- type ErrPossibleError
- 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 ProceduralIterator
- type RoutineFunc
- type SimpleIterator
- type SliceIterator
- type Slicer
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assert ¶
Assert panics if the condition is false.
Parameters:
- cond: The condition to check.
- msg: The message to show if the condition is false.
The panic message is the string msg.
func AssertConv ¶ added in v0.1.1
AssertConv tries to convert the element to type T. If the conversion fails, it panics.
Parameters:
- elem: The element to check.
- var_name: The name of the variable.
Returns:
- T: The element converted to type T.
The panic message is the message "expected <var_name> to be of type <T>, got <elem> instead".
func AssertDerefNil ¶
AssertNil panics if the element is nil but returns the element dereferenced if it is not nil.
Parameters:
- elem: The element to check.
- param_name: The name of the parameter.
Returns:
- T: The element if it is not nil.
The panic message is the message "Parameter \"param_name\" must not be nil".
func AssertErr ¶
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) // panic("In SomeFunc(param1, param2) = err")
}
func AssertF ¶
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.
The panic message is the equivalent of fmt.Sprintf(format, args).
func AssertNil ¶
AssertNil panics if the element is nil but returns the element dereferenced if it is not nil.
Parameters:
- elem: The element to check.
- param_name: The name of the parameter.
Returns:
- T: The element if it is not nil.
The panic message is the message "Parameter \"param_name\" must not be nil".
func AssertOk ¶
AssertOk panics if the condition is false.
Parameters:
- ok: The condition to check.
- format: The format of the message to show if the condition is false.
- 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) {
ok := SomeFunc(param1, param2)
AssertOk(ok, "SomeFunc(%s, %d)", param1, param2) // panic("In SomeFunc(param1, param2) = false")
}
func AssertParam ¶
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.
The panic message is of error *ErrInvalidParameter.
func AssertType ¶ added in v0.1.1
AssertType panics if the element is not of type T.
Parameters:
- elem: The element to check.
- allow_nil: If true, the element can be nil.
- var_name: The name of the variable.
The panic message is the message "expected <var_name> to be of type <T>, got <elem> instead".
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 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 Is ¶
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 ¶
IsDone checks if the iterator is exhausted.
Parameters:
- err: The error to check.
Returns:
- bool: True if the iterator is exhausted, false otherwise.
func IsErrIgnorable ¶
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 ¶
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 ¶
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 ¶
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 ¶
Max is a function that takes two parameters, a and b, of any type T according to the cmp.Ordered 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 ¶
Min is a function that takes two parameters, a and b, of any type T according to the cmp.Ordered interface 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 SliceCopy ¶
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 ¶
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.
Types ¶
type Builder ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
func (di *DynamicIterator[E, T]) Consume() (T, error)
Consume implements the Iterater interface.
func (*DynamicIterator[E, T]) Restart ¶
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 ¶
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 ¶
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 ¶
ChangeReason implements the Unwrapper interface.
type ErrAt ¶
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 ¶
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 ¶
ChangeReason implements the Unwrapper interface.
type ErrBefore ¶
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 ¶
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 ¶
ChangeReason implements the Unwrapper interface.
type ErrEmpty ¶
type ErrEmpty struct {
// Type is the type of the empty value.
Type string
}
ErrEmpty represents an error when a value is empty.
func NewErrEmpty ¶
NewErrEmpty creates a new ErrEmpty error.
Parameters:
- var_type: The type of the empty value.
Returns:
- *ErrEmpty: A pointer to the newly created ErrEmpty. Never returns nil.
type ErrExhaustedIter ¶
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 ¶
func NewErrExhaustedIter() *ErrExhaustedIter
NewErrExhaustedIter creates a new ErrExhaustedIter error.
Returns:
- *ErrExhaustedIter: A pointer to the new error.
func (*ErrExhaustedIter) Error ¶
func (e *ErrExhaustedIter) Error() string
Error implements the error interface.
Message: "iterator is exhausted"
type ErrGT ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (e *ErrIgnorable) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrIgnorable) Error ¶
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 ¶
func (e *ErrIgnorable) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrInvalidParameter ¶
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 ¶
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 ¶
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 ¶
func (e *ErrInvalidParameter) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrInvalidParameter) Error ¶
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 ¶
func (e *ErrInvalidParameter) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrInvalidRune ¶
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 ¶
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 ¶
func (e *ErrInvalidRune) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrInvalidRune) Error ¶
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 ¶
func (e *ErrInvalidRune) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrInvalidUsage ¶
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 ¶
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 ¶
func (e *ErrInvalidUsage) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrInvalidUsage) Error ¶
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 ¶
func (e *ErrInvalidUsage) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrLT ¶
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 ¶
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 ¶
type ErrNilValue struct{}
ErrNilValue represents an error when a value is nil.
func NewErrNilValue ¶
func NewErrNilValue() *ErrNilValue
NewErrNilValue creates a new ErrNilValue error.
Returns:
- *ErrNilValue: The new ErrNilValue error.
func (*ErrNilValue) Error ¶
func (e *ErrNilValue) Error() string
Error implements the error interface.
Message: "pointer must not be nil"
type ErrNoError ¶
type ErrNoError struct {
// Err is the reason for the no error error.
Err error
}
ErrNoError represents an error when no error occurs.
func NewErrNoError ¶
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 ¶
func (e *ErrNoError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrNoError) Error ¶
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 ¶
func (e *ErrNoError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrNotFound ¶
type ErrNotFound struct{}
ErrNotFound is an error type that is returned when a value is not found.
func NewErrNotFound ¶
func NewErrNotFound() *ErrNotFound
NewErrNotFound creates a new ErrNotFound error.
Returns:
- *ErrNotFound: A pointer to the new error.
func (*ErrNotFound) Error ¶
func (e *ErrNotFound) Error() string
Error implements the error interface.
Message: "not found"
type ErrOrSol ¶
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 ¶
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 ¶
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 ¶
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 ¶
GetErrors returns the list of errors.
Returns:
- []error: The list of errors.
func (*ErrOrSol[T]) GetSolutions ¶
func (e *ErrOrSol[T]) GetSolutions() []T
GetSolutions returns the list of solutions.
Returns:
- []T: The list of solutions.
type ErrOutOfBounds ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
type ErrPanic struct {
// Value is the value that caused the panic.
Value any
}
ErrPanic represents an error when a panic occurs.
func NewErrPanic ¶
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 ¶
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 ¶
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 ¶
func (e *ErrPossibleError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrPossibleError) Error ¶
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 ¶
func (e *ErrPossibleError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrUnexpectedError ¶
type ErrUnexpectedError struct {
// Reason is the reason for the unexpected error.
Reason error
}
ErrUnexpectedError represents an error that occurs unexpectedly.
func NewErrUnexpectedError ¶
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 ¶
func (e *ErrUnexpectedError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrUnexpectedError) Error ¶
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 ¶
func (e *ErrUnexpectedError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrUnexpectedType ¶
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 ¶
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 ¶
func (e *ErrUnexpectedType[T]) Error() string
Error implements the error interface.
Message: "type <type> is not a valid <kind> type"
type ErrVariableError ¶
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 ¶
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 ¶
func (e *ErrVariableError) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrVariableError) Error ¶
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 ¶
func (e *ErrVariableError) Unwrap() error
Unwrap implements the Unwrapper interface.
type ErrWhile ¶
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 ¶
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 ¶
ChangeReason implements the Unwrapper interface.
type ErrWhileAt ¶
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 ¶
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 ¶
func (e *ErrWhileAt) ChangeReason(reason error)
ChangeReason implements the Unwrapper interface.
func (*ErrWhileAt) Error ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ProceduralIterator ¶
ProceduralIterator is a struct that allows iterating over a collection of iterators of type Iterater[T].
func NewProceduralIterator ¶
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 ¶
func (pi *ProceduralIterator[E, T]) Consume() (T, error)
Consume implements the Iterater interface.
func (*ProceduralIterator[E, T]) Restart ¶
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 ¶
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 ¶
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 ¶
func (iter *SimpleIterator[T]) Consume() (T, error)
Consume implements the Iterater interface.
func (*SimpleIterator[T]) Restart ¶
func (iter *SimpleIterator[T]) Restart()
Restart implements the Iterater interface.
type SliceIterator ¶
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 ¶
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 ¶
func (pi *SliceIterator[T]) Consume() (T, error)
Consume implements the Iterater interface.
func (*SliceIterator[T]) Restart ¶
func (pi *SliceIterator[T]) Restart()
Restart implements the Iterater interface.
type Slicer ¶
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 ¶
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.