ListLike

package
v0.2.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ListLike provides a Lister interface that defines methods for a list data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LimitedArrayList

type LimitedArrayList[T any] struct {
	// contains filtered or unexported fields
}

LimitedArrayList is a generic type that represents a list data structure with or without a limited capacity. It is implemented using an array.

func NewLimitedArrayList

func NewLimitedArrayList[T any](capacity int, values ...T) *LimitedArrayList[T]

NewLimitedArrayList is a function that creates and returns a new instance of a LimitedArrayList.

Parameters:

  • capacity: An integer that represents the maximum number of elements the list. can hold. If the capacity is negative, the value is converted to a positive value.
  • values: A variadic parameter of type T, which represents the initial values to be stored in the list.

Returns:

  • *LimitedArrayList[T]: A pointer to the newly created LimitedArrayList.

func (*LimitedArrayList[T]) Append

func (list *LimitedArrayList[T]) Append(value T) error

Append is a method of the LimitedArrayList type. It is used to add an element to the end of the list.

Panics with an error of type *ErrFullList if the list is full.

Parameters:

  • value: A pointer to an element of type T to be added to the list.

func (*LimitedArrayList[T]) Capacity

func (list *LimitedArrayList[T]) Capacity() (int, bool)

Capacity is a method of the LimitedArrayList type. It returns the maximum number of elements the list can hold.

Returns:

  • optional.Int: An optional integer that represents the maximum number of elements the list can hold.

func (*LimitedArrayList[T]) Clear

func (list *LimitedArrayList[T]) Clear()

Clear is a method of the LimitedArrayList type. It is used to remove all elements from the list.

func (*LimitedArrayList[T]) Copy

func (list *LimitedArrayList[T]) Copy() itf.Copier

Copy is a method of the LimitedArrayList type. It is used to create a shallow copy of the list.

Returns:

  • itf.Copier: A copy of the list.

func (*LimitedArrayList[T]) CutNilValues

func (list *LimitedArrayList[T]) CutNilValues()

CutNilValues is a method of the LimitedArrayList type. It is used to remove all nil values from the list.

func (*LimitedArrayList[T]) DeleteFirst

func (list *LimitedArrayList[T]) DeleteFirst() (T, error)

DeleteFirst is a method of the LimitedArrayList type. It is used to remove and return the first element in the list.

Panics with an error of type *ErrInvalidOperation if the list is empty.

Returns:

  • T: The first element in the list.

func (*LimitedArrayList[T]) DeleteLast

func (list *LimitedArrayList[T]) DeleteLast() (T, error)

DeleteLast is a method of the LimitedArrayList type. It is used to remove and return the last element in the list.

Panics with an error of type *ErrInvalidOperation if the list is empty.

Returns:

  • T: The last element in the list.

func (*LimitedArrayList[T]) IsEmpty

func (list *LimitedArrayList[T]) IsEmpty() bool

IsEmpty is a method of the LimitedArrayList type. It checks if the list is empty.

Returns:

  • bool: A boolean value that is true if the list is empty, and false otherwise.

func (*LimitedArrayList[T]) IsFull

func (list *LimitedArrayList[T]) IsFull() bool

IsFull is a method of the LimitedArrayList type. It checks if the list is full.

Returns:

  • isFull: A boolean value that is true if the list is full, and false otherwise.

func (*LimitedArrayList[T]) Iterator

func (list *LimitedArrayList[T]) Iterator() itf.Iterater[T]

Iterator is a method of the LimitedArrayList type. It returns an iterator for the list.

Returns:

  • itf.Iterater[T]: An iterator for the list.

func (*LimitedArrayList[T]) PeekFirst

func (list *LimitedArrayList[T]) PeekFirst() (T, error)

PeekFirst is a method of the LimitedArrayList type. It is used to return the first element in the list without removing it.

Panics with an error of type *ErrInvalidOperation if the list is empty.

Returns:

  • T: A pointer to the first element in the list.

func (*LimitedArrayList[T]) PeekLast

func (list *LimitedArrayList[T]) PeekLast() (T, error)

PeekLast is a method of the LimitedArrayList type. It is used to return the last element in the list without removing it.

Panics with an error of type *ErrInvalidOperation if the list is empty.

Returns:

  • T: The last element in the list.

func (*LimitedArrayList[T]) Prepend

func (list *LimitedArrayList[T]) Prepend(value T) error

Prepend is a method of the LimitedArrayList type. It is used to add an element to the end of the list.

Panics with an error of type *ErrFullList if the list is full.

Parameters:

  • value: A pointer to an element of type T to be added to the list.

func (*LimitedArrayList[T]) Size

func (list *LimitedArrayList[T]) Size() int

Size is a method of the LimitedArrayList type. It returns the number of elements in the list.

Returns:

  • int: An integer that represents the number of elements in the list.

func (*LimitedArrayList[T]) Slice

func (list *LimitedArrayList[T]) Slice() []T

Slice is a method of the LimitedArrayList type that returns a slice of type T containing the elements of the list.

Returns:

  • []T: A slice of type T containing the elements of the list.

func (*LimitedArrayList[T]) String

func (list *LimitedArrayList[T]) String() string

String is a method of the LimitedArrayList type. It returns a string representation of the list with information about its size, capacity, and elements.

Returns:

  • string: A string representation of the list.

type LimitedLinkedList

type LimitedLinkedList[T any] struct {
	// contains filtered or unexported fields
}

LimitedLinkedList is a generic type that represents a list data structure with or without a limited capacity, implemented using a linked list.

func NewLimitedLinkedList

func NewLimitedLinkedList[T any](values ...T) *LimitedLinkedList[T]

NewLimitedLinkedList is a function that creates and returns a new instance of a LimitedLinkedList.

Parameters:

  • values: A variadic parameter of type T, which represents the initial values to be stored in the list.

Returns:

  • *LimitedLinkedList[T]: A pointer to the newly created LimitedLinkedList.

func (*LimitedLinkedList[T]) Append

func (list *LimitedLinkedList[T]) Append(value T) error

Append is a method of the LimitedLinkedList type. It is used to add an element to the end of the list.

Panics with an error of type *ErrFullList if the list is full.

Parameters:

  • value: An element of type T to be added to the list.

func (*LimitedLinkedList[T]) Capacity

func (list *LimitedLinkedList[T]) Capacity() (int, bool)

Capacity is a method of the LimitedLinkedList type. It is used to return the maximum number of elements the list can hold.

Returns:

  • optional.Int: An optional integer that represents the maximum number of elements the list can hold.

func (*LimitedLinkedList[T]) Clear

func (list *LimitedLinkedList[T]) Clear()

Clear is a method of the LimitedLinkedList type. It is used to remove all elements from the list.

func (*LimitedLinkedList[T]) Copy

func (list *LimitedLinkedList[T]) Copy() itf.Copier

Copy is a method of the LimitedLinkedList type. It is used to create a shallow copy of the list.

Returns:

  • itf.Copier: A copy of the list.

func (*LimitedLinkedList[T]) CutNilValues

func (list *LimitedLinkedList[T]) CutNilValues()

CutNilValues is a method of the LimitedLinkedList type. It is used to remove all nil values from the list.

func (*LimitedLinkedList[T]) DeleteFirst

func (list *LimitedLinkedList[T]) DeleteFirst() (T, error)

DeleteFirst is a method of the LimitedLinkedList type. It is used to remove and return the first element in the list.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The first element in the list.

func (*LimitedLinkedList[T]) DeleteLast

func (list *LimitedLinkedList[T]) DeleteLast() (T, error)

DeleteLast is a method of the LimitedLinkedList type. It is used to remove and return the last element in the list.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • T: The last element in the list.

func (*LimitedLinkedList[T]) IsEmpty

func (list *LimitedLinkedList[T]) IsEmpty() bool

IsEmpty is a method of the LimitedLinkedList type. It is used to check if the list is empty.

Returns:

  • bool: A boolean value that is true if the list is empty, and false otherwise.

func (*LimitedLinkedList[T]) IsFull

func (list *LimitedLinkedList[T]) IsFull() bool

IsFull is a method of the LimitedLinkedList type. It is used to check if the list is full.

Returns:

  • isFull: A boolean value that is true if the list is full, and false otherwise.

func (*LimitedLinkedList[T]) Iterator

func (list *LimitedLinkedList[T]) Iterator() itf.Iterater[T]

Iterator is a method of the LimitedLinkedList type. It is used to return an iterator for the list.

Returns:

  • itf.Iterater[T]: An iterator for the list.

func (*LimitedLinkedList[T]) PeekFirst

func (list *LimitedLinkedList[T]) PeekFirst() (T, error)

PeekFirst is a method of the LimitedLinkedList type. It is used to return the first element in the list without removing it.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • value: The first element in the list.

func (*LimitedLinkedList[T]) PeekLast

func (list *LimitedLinkedList[T]) PeekLast() (T, error)

PeekLast is a method of the LimitedLinkedList type. It is used to return the last element in the list without removing it.

Panics with an error of type *ErrCallFailed if the list is empty.

Returns:

  • value: The last element in the list.

func (*LimitedLinkedList[T]) Prepend

func (list *LimitedLinkedList[T]) Prepend(value T) error

Prepend is a method of the LimitedLinkedList type. It is used to add an element to the end of the list.

Panics with an error of type *ErrInvalidOperation if the list is full.

Parameters:

  • value: An element of type T to be added to the list.

func (*LimitedLinkedList[T]) Size

func (list *LimitedLinkedList[T]) Size() int

Size is a method of the LimitedLinkedList type. It is used to return the current number of elements in the list.

Returns:

  • int: An integer that represents the current number of elements in the list.

func (*LimitedLinkedList[T]) Slice

func (list *LimitedLinkedList[T]) Slice() []T

Slice is a method of the LimitedLinkedList type that returns a slice of type T

Returns:

  • []T: A slice of type T.

func (*LimitedLinkedList[T]) String

func (list *LimitedLinkedList[T]) String() string

String is a method of the LimitedLinkedList type. It returns a string representation of the list with information about its size, capacity, and elements.

Returns:

  • string: A string representation of the list.

type LimitedLister

type LimitedLister[T any] interface {
	// The Append method adds a value of type T to the end of the list.
	Append(value T) error

	// The DeleteFirst method is a convenience method that deletefirsts an element from
	// the list and returns it.
	// If the list is empty, it will panic.
	DeleteFirst() (T, error)

	// PeekFirst is a method that returns the value at the front of the list without
	// removing it.
	// If the list is empty, it will panic.
	PeekFirst() (T, error)

	// The Prepend method adds a value of type T to the end of the list.
	Prepend(value T) error

	// The DeleteLast method is a convenience method that deletelasts an element from the
	// list and returns it.
	// If the list is empty, it will panic.
	DeleteLast() (T, error)

	// PeekLast is a method that returns the value at the front of the list without
	// removing it.
	// If the list is empty, it will panic.
	PeekLast() (T, error)

	// ListLike[T] is an interface that defines methods for a list data structure.
	ListLike.ListLike[T]

	// The Capacity method returns the maximum number of elements that the list can hold.
	Capacity() (int, bool)

	// The IsFull method checks if the list is full, meaning it has reached its maximum
	// capacity and cannot accept any more elements.
	IsFull() bool
}

Lister is an interface that defines methods for a list data structure. It includes methods to add and remove elements, check if the list is empty or full, get the size of the list, convert the list to a slice, clear the list, and get a string representation of the list.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL