jam.types.base.sequences.array module

class jam.types.base.sequences.array.Array(initial: Sequence[T] = [], codec: Codec[T] | None = None)[source]

Bases: BaseSequence, Generic[T]

Fixed-length array is an extension of the BaseSequence, to only allow fixed length arrays.

The array has a fixed length, append, extend, pop, insert, remove, and clear methods are not supported. Elements can be: - Set/Updated at any index - Swapped with another element at any index - Get from any index

__init__(initial: Sequence[T] = [], codec: Codec[T] | None = None)[source]

Initialize array.

Parameters:

initial – Required initial values

Raises:
  • TypeError – If elements are not all of the same Codable type

  • ValueError – If initial values don’t match fixed length

__setitem__(index: int | slice, value: T | Sequence[T]) None[source]

Set item at index or slice.

append(value: T) None[source]

Append value to end of vector.

Parameters:

value – Value to append. Must be instance of the same type as other elements.

Raises:

TypeError – If value is not of the correct type

pop(index: int = -1) T[source]

Remove and return item at index.

Parameters:

index – Index of item to remove

Returns:

Removed item

Raises:

IndexError – If index out of range

insert(index: int, value: T) None[source]

Insert value at index.

Parameters:
  • index – Index to insert at

  • value – Value to insert. Must be instance of the same type as other elements.

Raises:

TypeError – If value is not of the correct type

remove(value: T) None[source]

Remove first occurrence of value.

Parameters:

value – Value to remove

Raises:

ValueError – If value not found

clear() None[source]

Clear all elements.

extend(values: Sequence[T]) None[source]

Extend vector with values.

Parameters:

values – Values to add. Must all be instances of the same type as existing elements.

Raises:

TypeError – If values are not all of the correct type

jam.types.base.sequences.array.decodable_array(length: int, element_type: Type[T]) Callable[[Type[Any]], Type[Any]][source]

Decorator that creates a fixed-length array type with a specific element type.

This decorator configures the array class with: 1. Fixed length 2. Element type validation 3. Custom decode_from implementation