queue

package
v0.0.0-...-21ef4fc Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T ds.Type] struct {
	Items []T
}

func (*Queue[T]) Dequeue

func (this *Queue[T]) Dequeue() T

Dequeue: Remove an element from the start of the Queue, and return it.

func (*Queue[T]) Enqueue

func (this *Queue[T]) Enqueue(items ...T) int

Enqueue: Add to the start of the Queue.

func (*Queue[T]) Every

func (this *Queue[T]) Every(callback func(index int, value T) bool) bool

Every: Takes in a callback function that acts as an evaluator for each element. Returns a boolean. Returns `true` if all the callback on all elements returns true. Returns `false` on encountering an element that the callback evaluates as false. Stops and exits method.

func (*Queue[T]) Filter

func (this *Queue[T]) Filter(callback func(index int, value T) bool) *Queue[T]

Filter: Takes in a Filter function that evaluates whether true or false on each item of the stack. Returns a new Queue of filtered items.

func (*Queue[T]) Find

func (this *Queue[T]) Find(callback func(index int, value T) bool) T

Find: Takes in a callback function that acts as an evaluator for each element. Returns the item if the callback function evaluates to true, zero-value of the Type otherwise

func (*Queue[T]) FindIndex

func (this *Queue[T]) FindIndex(callback func(index int, value T) bool) int

FindIndex: Takes in a callback function that acts as an evaluator for each element. Returns the index (position) of the first element that evaluates to true. Returns -1 if no element passes evaluation.

func (*Queue[T]) ForEach

func (this *Queue[T]) ForEach(callback func(index int, value T) error) *Queue[T]

ForEach: Takes in a Callback function to run for each element in the Queue. Returns nil always.

func (*Queue[T]) Get

func (this *Queue[T]) Get(index int) T

Get: Getter Function. Returns the value at Index

func (*Queue[T]) Includes

func (this *Queue[T]) Includes(item T) bool

Includes: Find whether the Queue contains an item. Returns true if found, false if not found

func (*Queue[T]) IndexOf

func (this *Queue[T]) IndexOf(item T) int

IndexOf: Returns the index of the first matching item in the Queue. If not found returns -1

func (*Queue[T]) Join

func (this *Queue[T]) Join(sep string) string

Join: Takes in a Separator string, joins the elements of the stack into a single string and returns it

func (*Queue[T]) LastIndexOf

func (this *Queue[T]) LastIndexOf(item T) int

LastIndexOf: Returns the index of the last matching item in the Queue. If not found returns -1

func (*Queue[T]) Map

func (this *Queue[T]) Map(callback func(index int, value T) T) *Queue[T]

Map: Modifies the elements of the stack with a mapping function that applies to each element. Returns a pointer to a new Slice.

func (*Queue[T]) Set

func (this *Queue[T]) Set(index int, value T)

Set: Setter Function. Takes in an index and a value.

func (*Queue[T]) Size

func (this *Queue[T]) Size() int

Size: Return the length of the stack

func (*Queue[T]) Slice

func (this *Queue[T]) Slice(start, end int) *Queue[T]

Slice: Takes a start and end index and returns a pointer to a new slice

func (*Queue[T]) Some

func (this *Queue[T]) Some(callback func(index int, value T) bool) bool

Some: Takes in a callback function that acts as an evaluator for each element. Returns a boolean. Returns `true` on encountering an element that the callback evaluates as true. Stops and exits method. Returns `false` if the callback returns false on all the elements.

func (*Queue[T]) Splice

func (this *Queue[T]) Splice(start, count int, items ...T) *Queue[T]

Splice: Mutates original Queue by removing elements starting at index. Takes three parameters total. Two parameters: `start` and `count` mutates the original Queue by removing items from a start index upto `count` number of items. The third is an optional variadic parameters that takes items of the same type as the Queue that it will be inserted at the index of removal. Returns the removed items as a new Queue

func (*Queue[T]) String

func (this *Queue[T]) String() string

String: Default formatting method.

Jump to

Keyboard shortcuts

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