Documentation
    Preparing search index...

    A container that stores and retrieves values by index.

    The Serializable equivalent of a vanilla JavaScript Array.

    Type Parameters

    Implements

    • SerializableObject
    Index

    Accessors

    Methods

    • Creates an iterator over the List's elements.

      Enables the List to be iterable directly.

      Returns IterableIterator<ListElement<T>>

      An iterator of the List's elements.

      const { containers } = createFutureMachine(futureDatabase);
      const list = containers.list.create<string[]>('hello', 'world');

      for (const value of list) {
      console.log(value);
      }
      // Console output:
      // hello
      // world
    • Retrieves the element at index index.

      Supports relative indexing from the end of the list using negative integers (e.g., -1 returns the last element).

      Type Parameters

      • U extends number

      Parameters

      • index: U

        The zero-based index of the element to retrieve.

      Returns T[U]

      The element at index index, or undefined if index is out of bounds.

      const { containers } = createFutureMachine(futureDatabase);
      const list = containers.list.create<[string, number]>('hello', 12);

      console.log(list.at(0));
      console.log(list.at(-1));
      console.log(list.at(5));
      // Console output:
      // hello
      // 12
      // undefined
    • Creates a new List where each element is mapped from the original List, transformed by callback.

      Type Parameters

      Parameters

      Returns List<U[]>

      The resulting List.

      const { containers } = createFutureMachine(futureDatabase);
      const list = containers.list.create<string[]>('hello', 'world');

      const mappedList = list.map((str) => `${str}_mapped`);
      // `mappedList` contains:
      // 0: hello_mapped
      // 1: world_mapped
    • Pops the last element off the List and returns it.

      Returns ListElement<T> | undefined

      The last element in the List.

      const { containers } = createFutureMachine(futureDatabase);
      const list = containers.list.create<string[]>('hello', 'world');

      console.log(list.pop());
      // Console output:
      // world
      // `list` now contains:
      // 0: hello
    • Pushes elements to the end of the List.

      Parameters

      Returns number

      The new length of the List.

      const { containers } = createFutureMachine(futureDatabase);
      const list = containers.list.create<string[]>('hello', 'world');

      list.push('fizz', 'buzz');
      // `list` now contains:
      // 0: hello
      // 1: world
      // 2: fizz
      // 3: buzz
    • Sets multiple elements starting at index to the values in elements.

      Parameters

      • elements: ListElement<T>[]

        An array of values to write into the List.

      • index: number

        The index to start writing the values to.

      Returns void

      const { containers } = createFutureMachine(futureDatabase);
      const list = containers.list.create<string[]>('hello', 'world', 'fizz');

      list.set(['lorem', 'ipsum'], 1);
      // `list` now contains:
      // 0: hello
      // 1: lorem
      // 2: ipsum
    • Creates an iterator over the List's elements.

      Returns IterableIterator<ListElement<T>>

      An iterator of the List's elements.

      const { containers } = createFutureMachine(futureDatabase);
      const list = containers.list.create<string[]>('hello', 'world');

      for (const value of list.values()) {
      console.log(value);
      }
      // Console output:
      // hello
      // world