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 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
- type Builder
- type DynamicIterator
- type ErrAfter
- 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 Iterable
- type Iterater
- type ProceduralIterator
- type SimpleIterator
- type SliceIterator
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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 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 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 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]) Errors ¶ added in v0.1.6
Errors returns the list of errors.
Returns:
- []error: The list of errors.
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 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 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 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 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)
}
Unwrapper is an interface that defines a method to unwrap an error.