tuple

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package tuple provides a generic, fixed-size tuple type with safe access and mutation.

Package tuple provides a generic, fixed-size tuple type with safe access and mutation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SyncTuple

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

SyncTuple represents a fixed-length collection of values of type T with thread-safety. It supports safe element access, mutation, and conversion to/from slices.

func NewSync

func NewSync[T any](vars ...T) *SyncTuple[T]

New creates a new SyncTuple from the given variadic values. The values are copied to ensure the SyncTuple does not alias external data.

func SyncFromSlice

func SyncFromSlice[T any](s []T) *SyncTuple[T]

FromSlice creates a new SyncTuple by copying the contents of the provided slice. The resulting Tuple has the same length as the input slice.

func (*SyncTuple[T]) Get

func (t *SyncTuple[T]) Get(index int) (T, bool)

Get returns the element at the specified index and a boolean indicating success. If the index is out of bounds, the zero value of T and false are returned.

func (*SyncTuple[T]) Len

func (t *SyncTuple[T]) Len() int

Len returns the number of elements in the Tuple.

func (*SyncTuple[T]) Set

func (t *SyncTuple[T]) Set(index int, v T) bool

Set updates the element at the specified index to the given value. It returns true if the operation was successful, or false if the index was out of bounds.

func (*SyncTuple[T]) String

func (t *SyncTuple[T]) String() string

String returns a string representation of the SyncTuple's contents.

func (*SyncTuple[T]) ToSlice

func (t *SyncTuple[T]) ToSlice() []T

ToSlice returns a copy of the SyncTuple's internal values as a slice.

type Tuple

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

Tuple represents a fixed-length collection of values of type T. It supports safe element access, mutation, and conversion to/from slices.

func FromSlice

func FromSlice[T any](s []T) *Tuple[T]

FromSlice creates a new Tuple by copying the contents of the provided slice. The resulting Tuple has the same length as the input slice.

func New

func New[T any](vars ...T) *Tuple[T]

New creates a new Tuple from the given variadic values. The values are copied to ensure the Tuple does not alias external data.

func (*Tuple[T]) Get

func (t *Tuple[T]) Get(index int) (T, bool)

Get returns the element at the specified index and a boolean indicating success. If the index is out of bounds, the zero value of T and false are returned.

func (*Tuple[T]) Len

func (t *Tuple[T]) Len() int

Len returns the number of elements in the Tuple.

func (*Tuple[T]) Set

func (t *Tuple[T]) Set(index int, v T) bool

Set updates the element at the specified index to the given value. It returns true if the operation was successful, or false if the index was out of bounds.

func (*Tuple[T]) String

func (t *Tuple[T]) String() string

String returns a string representation of the Tuple's contents.

func (*Tuple[T]) ToSlice

func (t *Tuple[T]) ToSlice() []T

ToSlice returns a copy of the Tuple's internal values as a slice.

Jump to

Keyboard shortcuts

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