| 20 | * (i.e., the arrays are immutable). |
| 21 | */ |
| 22 | export interface DataArray<T> { |
| 23 | /** The total number of elements in the array. */ |
| 24 | length: number; |
| 25 | |
| 26 | /** Applies the given function to the entire data array. Allows using function chaining while applying an arbitrary intermediate function. */ |
| 27 | chain<U>(op: (arr: DataArray<T>) => DataArray<U>): DataArray<U>; |
| 28 | |
| 29 | /** Filter the data array down to just elements which match the given predicate. */ |
| 30 | where(predicate: ArrayFunc<T, boolean>): DataArray<T>; |
| 31 | /** Alias for 'where' for people who want array semantics. */ |
| 32 | filter(predicate: ArrayFunc<T, boolean>): DataArray<T>; |
| 33 | |
| 34 | /** Map elements in the data array by applying a function to each. */ |
| 35 | map<U>(f: ArrayFunc<T, U>): DataArray<U>; |
| 36 | /** Map elements in the data array by applying a function to each, then flatten the results to produce a new array. */ |
| 37 | flatMap<U>(f: ArrayFunc<T, U[]>): DataArray<U>; |
| 38 | /** Mutably change each value in the array, returning the same array which you can further chain off of. */ |
| 39 | mutate(f: ArrayFunc<T, void>): DataArray<T>; |
| 40 | |
| 41 | /** Limit the total number of entries in the array to the given value. */ |
| 42 | limit(count: number): DataArray<T>; |
| 43 | /** |
| 44 | * Take a slice of the array. If `start` is undefined, it is assumed to be 0; if `end` is undefined, it is assumbed |
| 45 | * to be the end of the array. |
| 46 | */ |
| 47 | slice(start?: number, end?: number): DataArray<T>; |
| 48 | /** Concatenate the values in this data array with those of another iterable / data array / array. */ |
| 49 | concat(other: Iterable<T>): DataArray<T>; |
| 50 | |
| 51 | /** Return the first index of the given (optionally starting the search) */ |
| 52 | indexOf(element: T, fromIndex?: number): number; |
| 53 | /** Return the first element that satisfies the given predicate. */ |
| 54 | find(pred: ArrayFunc<T, boolean>): T | undefined; |
| 55 | /** Find the index of the first element that satisfies the given predicate. Returns -1 if nothing was found. */ |
| 56 | findIndex(pred: ArrayFunc<T, boolean>, fromIndex?: number): number; |
| 57 | /** Returns true if the array contains the given element, and false otherwise. */ |
| 58 | includes(element: T): boolean; |
| 59 | |
| 60 | /** |
| 61 | * Return a string obtained by converting each element in the array to a string, and joining it with the |
| 62 | * given separator (which defaults to ', '). |
| 63 | */ |
| 64 | join(sep?: string): string; |
| 65 | |
| 66 | /** |
| 67 | * Return a sorted array sorted by the given key; an optional comparator can be provided, which will |
| 68 | * be used to compare the keys in leiu of the default dataview comparator. |
| 69 | */ |
| 70 | sort<U>(key: ArrayFunc<T, U>, direction?: "asc" | "desc", comparator?: ArrayComparator<U>): DataArray<T>; |
| 71 | |
| 72 | /** |
| 73 | * Mutably modify the current array with an in place sort; this is less flexible than a regular sort in exchange |
| 74 | * for being a little more performant. Only use this is performance is a serious consideration. |
| 75 | */ |
| 76 | sortInPlace<U>(key: (v: T) => U, direction?: "asc" | "desc", comparator?: ArrayComparator<U>): DataArray<T>; |
| 77 | |
| 78 | /** |
| 79 | * Return an array where elements are grouped by the given key; the resulting array will have objects of the form |
no outgoing calls
no test coverage detected