import { Comparison, MapLike } from './core'; export declare const emptyArray: never[]; export type EqualityComparer = (a: T, b: T) => boolean; export declare function contains(array: readonly T[] | undefined, value: T, equalityComparer?: EqualityComparer): boolean; /** Array that is only intended to be pushed to, never read. */ export interface Push { push(...values: T[]): void; } /** * Appends a value to an array, returning the array. * * @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array * is created if `value` was appended. * @param value The value to append to the array. If `value` is `undefined`, nothing is * appended. */ export declare function append[number] | undefined>(to: TArray, value: TValue): [undefined, undefined] extends [TArray, TValue] ? TArray : NonNullable[number][]; export declare function append(to: T[], value: T | undefined): T[]; export declare function append(to: T[] | undefined, value: T): T[]; export declare function append(to: T[] | undefined, value: T | undefined): T[] | undefined; /** * Safely pushes the values of one array onto another array. This is the * same as receiver.push(...elementsToPush) except that it doesn't risk overflowing * the stack if elementsToPush is very large. */ export declare function appendArray(to: T[], elementsToPush: T[]): void; /** Works like Array.filter except that it returns a second array with the filtered elements. **/ export declare function partition(array: readonly T[], cb: (value: T) => boolean): [S[], T[]]; /** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */ export declare function find(array: readonly T[], predicate: (element: T, index: number) => element is U): U | undefined; export declare function find(array: readonly T[], predicate: (element: T, index: number) => boolean): T | undefined; /** * Appends a range of value to an array, returning the array. * * @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array * is created if `value` was appended. * @param from The values to append to the array. If `from` is `undefined`, nothing is * appended. If an element of `from` is `undefined`, that element is not appended. * @param start The offset in `from` at which to start copying values. * @param end The offset in `from` at which to stop copying values (non-inclusive). */ export declare function addRange(to: T[], from: readonly T[] | undefined, start?: number, end?: number): T[]; export declare function addRange(to: T[] | undefined, from: readonly T[] | undefined, start?: number, end?: number): T[] | undefined; export declare function insertAt(array: T[], index: number, value: T): T[]; export type Comparer = (a: T, b: T) => Comparison; export interface SortedReadonlyArray extends ReadonlyArray { ' __sortedArrayBrand': any; } export interface SortedArray extends Array { ' __sortedArrayBrand': any; } /** * Returns a new sorted array. */ export declare function cloneAndSort(array: readonly T[], comparer?: Comparer): SortedReadonlyArray; /** * Stable sort of an array. Elements equal to each other maintain their relative position in the array. */ export declare function stableSort(array: readonly T[], comparer: Comparer): SortedReadonlyArray; export declare function map(array: readonly T[], f: (x: T, i: number) => U): U[]; export declare function map(array: readonly T[] | undefined, f: (x: T, i: number) => U): U[] | undefined; export declare function some(array: readonly T[] | undefined): array is readonly T[]; export declare function some(array: readonly T[] | undefined, predicate: (value: T) => boolean): boolean; /** * Iterates through `array` by index and performs the callback on each element of array until the callback * returns a falsey value, then returns false. * If no such value is found, the callback is applied to each element of array and `true` is returned. */ export declare function every(array: readonly T[], callback: (element: T, index: number) => boolean): boolean; /** * Performs a binary search, finding the index at which `value` occurs in `array`. * If no such index is found, returns the 2's-complement of first index at which * `array[index]` exceeds `value`. * @param array A sorted array whose first element must be no larger than number * @param value The value to be searched for in the array. * @param keySelector A callback used to select the search key from `value` and each element of * `array`. * @param keyComparer A callback used to compare two keys in a sorted array. * @param offset An offset into `array` at which to start the search. */ export declare function binarySearch(array: readonly T[], value: T, keySelector: (v: T) => U, keyComparer: Comparer, offset?: number): number; /** * Performs a binary search, finding the index at which an object with `key` occurs in `array`. * If no such index is found, returns the 2's-complement of first index at which * `array[index]` exceeds `key`. * @param array A sorted array whose first element must be no larger than number * @param key The key to be searched for in the array. * @param keySelector A callback used to select the search key from each element of `array`. * @param keyComparer A callback used to compare two keys in a sorted array. * @param offset An offset into `array` at which to start the search. */ export declare function binarySearchKey(array: readonly T[], key: U, keySelector: (v: T) => U, keyComparer: Comparer, offset?: number): number; /** * Flattens an array containing a mix of array or non-array elements. * * @param array The array to flatten. */ export declare function flatten(array: (NonNullable[] | NonNullable)[]): T[]; /** * Retrieves nested objects by parsing chained properties. ie. "a.b.c" * Returns undefined if not found * @param object The object to query * @param property The property to be searched for in the object ie. "a.b.c" */ export declare function getNestedProperty(object: any, property: string): any; export declare function getOrAdd(map: MapLike, key: K, newValueFactory: () => V): V; /** * Remove matching item from the array in place. * Returns the given array itself. * @param array The array to operate on. * @param predicate Return true for an item to delete. */ export declare function removeArrayElements(array: T[], predicate: (item: T) => boolean): T[]; export declare function createMapFromItems(items: T[], keyGetter: (t: T) => string): Map; export declare function addIfUnique(arr: T[], t: T, equalityComparer?: EqualityComparer): T[]; export declare function getMapValues(m: Map, predicate: (k: K, v: V) => boolean): V[]; export declare function addIfNotNull(arr: T[], t: T): T[]; export declare function arrayEquals(c1: T[], c2: T[], predicate: (e1: T, e2: T) => boolean): boolean;