Tray

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tray

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

Tray is a struct that represents a tape.

func NewTray

func NewTray[T any](tape []T) *Tray[T]

NewTray creates a new Tray with the given tape.

Parameters:

  • tape: The tape to use.

Returns:

  • *Tray: A pointer to the new Tray.

func (*Tray[T]) ArrowEnd

func (t *Tray[T]) ArrowEnd()

ArrowEnd moves the arrow to the end of the tape.

func (*Tray[T]) ArrowStart

func (t *Tray[T]) ArrowStart()

ArrowStart moves the arrow to the start of the tape.

func (*Tray[T]) Delete

func (t *Tray[T]) Delete(n int) error

ReadLeft reads the element to the left of the arrow position.

Returns:

  • T: The element to the left of the arrow position.
  • error: An error if elements to the left of the arrow position cannot be found.

Errors:

  • *ers.ErrEmpty[*Tray]: If the tape is empty.
  • *ers.ErrInvalidParameter: If n is less than 0.

func (*Tray[T]) ExtendTapeOnLeft

func (t *Tray[T]) ExtendTapeOnLeft(elems ...T)

ExtendTapeOnLeft extends the tape on the left with the given elements.

Parameters:

  • elems: The elements to add.

func (*Tray[T]) ExtendTapeOnRight

func (t *Tray[T]) ExtendTapeOnRight(elems ...T)

ExtendTapeOnRight extends the tape on the right with the given elements.

Parameters:

  • elems: The elements to add.

func (*Tray[T]) Insert

func (t *Tray[T]) Insert(elems ...T)

Insert inserts the given elements to the tape at the arrow position.

Parameters:

  • elems: The elements to insert.

func (*Tray[T]) MoveLeft

func (t *Tray[T]) MoveLeft(n int) bool

MoveLeft moves the arrow to the left by n positions.

Parameters:

  • n: The number of positions to move the arrow.

Returns:

  • bool: True if the number of positions is equal to n, false otherwise.

func (*Tray[T]) MoveRight

func (t *Tray[T]) MoveRight(n int) bool

MoveRight moves the arrow to the right by n positions.

Parameters:

  • n: The number of positions to move the arrow.

Returns:

  • bool: True if the number of positions is equal to n, false otherwise.

func (*Tray[T]) Read

func (t *Tray[T]) Read() (T, error)

Read reads the element at the arrow position.

Returns:

  • T: The element at the arrow position.
  • error: An error of type *ers.Empty[*Tray] if the tape is empty.

func (*Tray[T]) ShiftLeftOfArrow

func (t *Tray[T]) ShiftLeftOfArrow(n int)

ShiftLeftOfArrow shifts the elements on the right of the arrow to the left by n positions.

Parameters:

  • n: The number of positions to shift the elements.

func (*Tray[T]) ShiftRightOfArrow

func (t *Tray[T]) ShiftRightOfArrow(n int)

ShiftRightOfArrow shifts the elements on the left of the arrow to the right by n positions.

Parameters:

  • n: The number of positions to shift the elements.

func (*Tray[T]) Write

func (t *Tray[T]) Write(elem T) error

Write writes the given element to the tape at the arrow position.

Parameters:

  • elem: The element to write.

Returns:

  • error: An error of type *ers.Empty[*Tray] if the tape is empty.

Jump to

Keyboard shortcuts

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