UNPKG

2.05 kBTypeScriptView Raw
1export declare namespace ArrayUtils {
2 interface Head<T> extends Array<T> {
3 head(): T;
4 }
5 interface Tail<T> extends Array<T> {
6 tail(): T;
7 }
8 interface Children<T> extends Array<T> {
9 children(): Tail<T>;
10 }
11 const TailImpl: {
12 tail<T>(this: T[]): T;
13 };
14 const HeadAndChildrenImpl: {
15 head<T>(this: T[]): T;
16 children<T_1>(this: T_1[]): Tail<T_1>;
17 };
18 interface HeadAndTail<T> extends Head<T>, Tail<T>, Children<T> {
19 }
20 function asTail<T>(array: Array<T>): Tail<T>;
21 function asHeadAndTail<T>(array: Array<T>): HeadAndTail<T>;
22 enum Sort {
23 LeftBeforeRight = -1,
24 RightBeforeLeft = 1,
25 Equal = 0
26 }
27 /**
28 * Performs a binary search algorithm over a sorted collection. Useful for cases
29 * when we need to perform a binary search over something that isn't actually an
30 * array, and converting data to an array would defeat the use of binary search
31 * in the first place.
32 *
33 * @param length The collection length.
34 * @param compareToKey A function that takes an index of an element in the
35 * collection and returns zero if the value at this index is equal to the
36 * search key, a negative number if the value precedes the search key in the
37 * sorting order, or a positive number if the search key precedes the value.
38 * @return A non-negative index of an element, if found. If not found, the
39 * result is -(n+1) (or ~n, using bitwise notation), where n is the index
40 * where the key should be inserted to maintain the sorting order.
41 */
42 function binarySearch2(length: number, compareToKey: (index: number) => number): number;
43 function partition<T>(array: T[], filter: (e: T, idx: number, arr: T[]) => boolean | undefined): [T[], T[]];
44 /**
45 * @returns New array with all falsy values removed. The original array IS NOT modified.
46 */
47 function coalesce<T>(array: ReadonlyArray<T | undefined | null>): T[];
48}
49//# sourceMappingURL=array-utils.d.ts.map
\No newline at end of file