arrayTools.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. import type { Tuple } from "../types";
  2. /**
  3. * Class containing a set of static utilities functions for arrays.
  4. */
  5. export declare class ArrayTools {
  6. /**
  7. * Returns an array of the given size filled with elements built from the given constructor and the parameters.
  8. * @param size the number of element to construct and put in the array.
  9. * @param itemBuilder a callback responsible for creating new instance of item. Called once per array entry.
  10. * @returns a new array filled with new objects.
  11. */
  12. static BuildArray<T>(size: number, itemBuilder: () => T): Array<T>;
  13. /**
  14. * Returns a tuple of the given size filled with elements built from the given constructor and the parameters.
  15. * @param size he number of element to construct and put in the tuple.
  16. * @param itemBuilder a callback responsible for creating new instance of item. Called once per tuple entry.
  17. * @returns a new tuple filled with new objects.
  18. */
  19. static BuildTuple<T, N extends number>(size: N, itemBuilder: () => T): Tuple<T, N>;
  20. }
  21. /**
  22. * Defines the callback type used when an observed array function is triggered.
  23. * @internal
  24. */
  25. export type _ObserveCallback = (functionName: string, previousLength: number) => void;
  26. /**
  27. * Observes an array and notifies the given observer when the array is modified.
  28. * @param array Defines the array to observe
  29. * @param callback Defines the function to call when the array is modified (in the limit of the observed array functions)
  30. * @returns A function to call to stop observing the array
  31. * @internal
  32. */
  33. export declare function _ObserveArray<T>(array: T[], callback: _ObserveCallback): () => void;