Skip to content

Provide an interface for abstract lists. An abstract list behaves like a read-only array, but without storage. It can virtually store an infinite number of elements. It's meant for working flexibly with arrays. Regular arrays can be used as abstract lists as well.

License

jacklehamster/abstract-list

Repository files navigation

abstract-list

npm version

Abstract list for working with arrays that aren't really arrays.

Usage

//   This is an abstract list
const arrayList: List<number> = [1, 2, 3];

//  This is also an abstract list
const aList: List<number> = {
  at(index) {
    return index;
  },
  length: Number.MAX_SAFE_INTEGER,
};

//  This is a giant list for which elem.at(x) === x^2
const squareList: List<number> = {
  at(index) {
    return index * index;
  },
  length: Number.MAX_SAFE_INTEGER,
};

In bun-engine, abstract lists are used to represent a large number sprites flexibly, without storing each sprite structure.

Install bun

https://bun.sh/

curl -fsSL https://bun.sh/install | bash

About

Provide an interface for abstract lists. An abstract list behaves like a read-only array, but without storage. It can virtually store an infinite number of elements. It's meant for working flexibly with arrays. Regular arrays can be used as abstract lists as well.

Resources

License

Stars

Watchers

Forks

Packages

No packages published