jacklehamster / abstract-list

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.

Home Page:https://jacklehamster.github.io/abstract-list/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

abstract-list

npm version

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

icon

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.

https://jacklehamster.github.io/abstract-list/

License:MIT License


Languages

Language:TypeScript 98.3%Language:Shell 1.7%