Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyStack occurs when the stack is empty. This error can be checked // with the == operator. // // Format: // "stack is empty" ErrEmptyStack error )
Functions ¶
This section is empty.
Types ¶
type ArrayStack ¶
type ArrayStack[E any] struct { // contains filtered or unexported fields }
ArrayStack is a generic stack implemented using an array.
func (*ArrayStack[E]) Reset ¶
func (as *ArrayStack[E]) Reset() error
Reset implements common.Resetter.
type Collection ¶
type Collection[E any] interface { // Slice returns a slice of the elements in the collection. // // Returns: // - []E: A slice of the elements in the collection. Slice() []E }
Collection is an interface that represents a collection of elements.
type CoreStack ¶
type CoreStack[E any] interface { // Push pushes an element onto the stack. // // Parameters: // - e: The element to be pushed onto the stack. // // Returns: // - error: An error if the element could not be pushed onto the stack. // // Errors: // - common.ErrNilReceiver: If the receiver is nil. Push(e E) error // Pop pops an element from the stack. // // Returns: // - E: The element that was popped from the stack. // - error: An error if the element could not be popped from the stack. // // Errors: // - common.ErrNilReceiver: If the receiver is nil. // - ErrEmptyStack: If the stack is empty. Pop() (E, error) // IsEmpty checks if the stack is empty. // // Returns: // - bool: True if the stack is empty, false otherwise. IsEmpty() bool }
CoreStack is a generic stack interface.
type RefusableStack ¶
type RefusableStack[E any] struct { // contains filtered or unexported fields }
RefusableStack is a stack that can be reset.
func RefusableOf ¶
func RefusableOf[E any](stack Stack[E]) (*RefusableStack[E], error)
RefusableOf creates a new RefusableStack from the provided stack.
Parameters:
- stack: The stack to be wrapped in a RefusableStack.
Returns:
- *RefusableStack[E]: A pointer to the newly created RefusableStack.
- error: An error if the provided stack is nil.
Errors:
- common.ErrBadParam: If the stack parameter is nil.
func (*RefusableStack[E]) Accept ¶
func (s *RefusableStack[E]) Accept() error
Accept resets the popped stack, effectively "accepting" the popped elements.
Returns:
- error: An error if the receiver is nil or if the popped stack could not be reset.
Errors:
- common.ErrNilReceiver: If the receiver is nil.
func (*RefusableStack[E]) Pop ¶
func (s *RefusableStack[E]) Pop() (E, error)
Pop implements CoreStack.
func (RefusableStack[E]) Popped ¶
func (s RefusableStack[E]) Popped() []E
Popped returns the elements that were popped from the stack.
Returns:
- []E: The elements that were popped from the stack.
func (*RefusableStack[E]) Push ¶
func (s *RefusableStack[E]) Push(e E) error
Push implements CoreStack.
func (*RefusableStack[E]) Refuse ¶
func (s *RefusableStack[E]) Refuse() error
Refuse transfers all elements from the stack to the popped stack, effectively "refusing" the stack.
Returns:
- error: An error if the receiver is nil.
Errors:
- common.ErrNilReceiver: If the receiver is nil.
func (*RefusableStack[E]) Reset ¶
func (s *RefusableStack[E]) Reset() error
Reset implements common.Resetter.
func (RefusableStack[E]) Slice ¶
func (s RefusableStack[E]) Slice() []E
Slice implements Collection.