Skip to content
This repository has been archived by the owner on Mar 14, 2018. It is now read-only.

Better list support #13

Open
thosakwe opened this issue Feb 17, 2017 · 0 comments
Open

Better list support #13

thosakwe opened this issue Feb 17, 2017 · 0 comments

Comments

@thosakwe
Copy link
Collaborator

thosakwe commented Feb 17, 2017

Requires #14, as well as #15.

abstract final class Lists {
  @external()
  static emptyList<T>():T[];

  @external()
  static create<T>(size:int):T[];

  @external()
  static fill<T>(list:T[], value:T):void;

  @external()
  static copy<T>(from:T[], to:T[], offset:int, len:int):void;

  @external()
  static size<T>(list:T[]):int;

  static duplicate<T>(list:T[]):T[] {
    let sz = size(list);
    let result = create(sz);
    copy(list, result, 0, sz);
    return result;
  }

  static add<T>(list:T[], value:T):T[] {
    let sz = size(list);
    let result = create(sz + 1);
    copy(list, result, 0, sz);
    result[sz] = value;
    return result;
  }
}
// And more...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant