slice

package
v0.0.0-...-81dff9f Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIndexOutOfBounds = errors.New("index out of bounds")
)

Functions

This section is empty.

Types

type Slice

type Slice[TItem any] interface {
	collection.Collection[TItem]

	// Unmarshal returns the underlying Go slice
	Unmarshal() []TItem

	// First returns the first item in the Slice
	First() *TItem

	// Last returns the last item in the Slice
	Last() *TItem

	// Add appends the given item to the Slice
	Add(TItem)

	// Get returns the item at the given index
	// in the Slice, otherwise returns nil and
	// the respective error
	Get(int) (*TItem, error)

	// Set value at the given index to the given
	// item in the Slice, returning any resulting
	// error
	Set(int, TItem) error

	// Insert adds the given item at the given index
	// in the Slice, returning any resulting error
	Insert(int, TItem) error

	// Remove removes and returns the item at the given
	// index in the size, otherwise returns nil and the
	// respective error
	Remove(int) (*TItem, error)
}

Slice provides a thin abstraction over the primitive Go slice

func From

func From[TItem any](c collection.Collection[TItem]) Slice[TItem]

func Marshal

func Marshal[TItem any](s []TItem) Slice[TItem]

From returns a Slice by casting a Go slice

func New

func New[TItem any](size, capacity int) Slice[TItem]

New creates a new Slice with the given size and capacity

Jump to

Keyboard shortcuts

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