Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@luminela/ts-collections
Advanced tools
A collection of wrappers for common data structures in TypeScript
Readme
A simple collections library for TypeScript.
const list = new List<string>();
You can pass an Iterable object to the constructor.
const array = [1, 2, 3, 4, 5];
const list = new List(array);
You can also pass an equality comparator that will be used instead of default equality comparator. You should always define this custom equality comparator if your List contains complex objects.
const person1 = new Person("John", "Doe", 21);
const person2 = new Person("John", "Doe", 55);
const comparator: EqualityComparator = (p1, p2) => p1.name === p2.name && p1.surname == p2.surname && p1.age == p2.age;
const list = new List([person1, person2], comparator);
const list = new LinkedList<string>();
You can pass an Iterable object to the constructor.
const array = [1, 2, 3, 4, 5];
const list = new LinkedList(array);
You can also pass an equality comparator that will be used instead of default equality comparator. You should always define this custom equality comparator if your LinkedList contains complex objects.
const person1 = new Person("John", "Doe", 21);
const person2 = new Person("John", "Doe", 55);
const comparator: EqualityComparator = (p1, p2) => p1.name === p2.name && p1.surname == p2.surname && p1.age == p2.age;
const list = new LinkedList([person1, person2], comparator);
const tree = new RedBlackTree<string>();
You can pass an Iterable object to the constructor.
const array = [1, 2, 3, 4, 5];
const tree = new RedBlackTree(array);
You can also pass an order comparator that will be used instead of default order comparator. You should always define this custom order comparator if your RedBlackTree contains complex objects.
const person1 = new Person("John", "Doe", 21);
const person2 = new Person("John", "Doe", 55);
const comparator: OrderComparator = (p1, p2) => p1.name.localeCompare(p2.name);
const tree = new RedBlackTree(comparator, [person1, person2]);
const treeSet = new TreeSet<string>();
You can pass an Iterable object to the constructor.
const array = [1, 2, 3, 4, 5];
const treeSet = new TreeSet(array);
You can also pass an order comparator that will be used instead of default order comparator. You should always define this custom order comparator if your TreeSet contains complex objects.
const person1 = new Person("John", "Doe", 21);
const person2 = new Person("John", "Doe", 55);
const comparator: OrderComparator = (p1, p2) => p1.name.localeCompare(p2.name);
const treeSet = new TreeSet([person1, person2], comparator);
Dictionary is implemented as a sorted dictionary by using RedBlackTree internally.
const dictionary = new Dictionary<number, Person>();
You can pass an Iterable<KeyValuePair<TKey, TValue>> object to the constructor.
const array: KeyValuePair<number, string> = [
new KeyValuePair(1, "a"),
new KeyValuePair(2, "b")
]
const dictionary = new Dictionary(null, null, array);
You can also pass an order comparator, and an equality comparator that will be used instead of default order and equality comparators. You should always define these custom comparators if your dictionary contains complex objects.
Dictionary has two comparators.
You can pass null to use default comparators. However, it will not work properly when the objects are complex.
const personOrderComparator: OrderComparator = (p1: Person, p2: Person) => p1.name.localeCompare(p2.name);
const personEqualityComparator: EqualityComparator = (p1, p2) => p1.name === p2.name && p1.surname == p2.surname && p1.age == p2.age;
const dictionary1 = new Dictionary<Person, string>(personOrderComparator);
const dictionary2 = new Dictionary<string, Person>(null, personEqualityComparator);
Both of these interfaces are implemented in LinkedList class.
const queue: IQueue<string> = new LinkedList<string>();
const deque: IDeque<string> = new LinkedList<string>();
All the provided classes in the library has integrated enumerable support.
const list = new List([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
const list2 = list.select(n => n * n).takeWhile(n <= 25).skipWhile(n < 10).orderByDescending(n => n).toList();
const array = list.takeLast(5).toArray();
You can also use Enumerable with plain arrays.
const array = Enumerable.from([1, 2, 3, 4, 5]).where(n => n % 2 !== 0).toArray();
A simple documentation can be found at: https://luminela.github.io/ts-collections/
FAQs
A collection of wrappers for common data structures in TypeScript
We found that @luminela/ts-collections demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.