dojo / core

:rocket: Dojo 2 - language helpers and utilities.
http://dojo.io
Other
213 stars 62 forks source link

Proposal: List #217

Closed kitsonk closed 7 years ago

kitsonk commented 7 years ago

For API consistency, it would be great if we had a List, which would essentially be an Array, but with an API that is consistent with Map and Set, so that operations could be performed on it without having to bifurcate the code path to deal with the collection.

The interface should be something like:

interface List<T> {
    readonly size: number;

    add(value: T): this;
    clear(): void;
    delete(idx: number): boolean;
    entries(): Iterator<[ number, T ]>;
    forEach(fn: (value: T, idx: number, list: this) => void, thisArg?: any): void;
    has(idx: number): boolean;
    keys(): Iterator<number>;
    values(): Iterator<T>;
    [Symbol.iterator]: Iterator<[ number, T ]>;

    includes(value: T): boolean;
    indexOf(value: T): number;
    lastIndexOf(value: T): number;
}

Are there other array extras we should have, like reduce and reduceLeft, some, every, etc?

kitsonk commented 7 years ago

Oh and push, pop, splice, join? The constructor should take and Iterable like other collections as well.